Script entry points and input parameters

<< Click to Display Table of Contents >>

Navigation:  Programming Mechworks PDM > DBWCommandShell > Programmer's Guide >

Script entry points and input parameters

available from build: 20041209

Description

It is possible to assign Entry Points or Input Parameters to the VBS scripts by encoding the script file name as follows:

Entry Point

Script_File_Name&Entry_point

The subroutine Entry_point will be executed in the script.

Input Parameters

Script_File_Name&@Input_Parameter[\r\nInput_Parameter[\r\nInput_Parameter[…]]]

The listed Input_Parameter will be included in the Global Variables space of the script.

Example

Pass the parameters:

myPar1=30

myPar2=30
myPar3="My String"

 

to the script test.vbs in a variant note:

@DBW=.VBSCRIPT Test.vbs&@myPar1=20\r\nmyPar2=30\r\nmyPar3="My string"

The test.vbs script can be written as follows:

Sub main()

 DBWInit(TRUE)
 DBWMsgBox _
  "myParameter1=" & myPar1 & vbcrlf &_
  "myParameter2=" & myPar2 & vbcrlf &_
  "myParameter3=" & myPar3
 ...
end sub

to the ExecScript shell command (vbscript):

Here you need a launcher script that after variables assignment, executes the real script; the first called LauncherTest.vbs and the latter called Test.vbs

the LauncherTest.vbs:

Sub Main()

 DBWInit(TRUE)
 myPar1 = 5
 myPar2 = 10
 DBWShell("ExecScript Test.vbs&@par1=" & Chr(34) & myPar1 & Chr(34) & "\r\npar2=" &Chr(34) & myPar2 & Chr(34))
End Sub

please note it's mandatory to specify parameters between double quotes that are passed in vbscript as Chr(34)

The test.vbs

Sub Main()

    DBWInit(TRUE)
 dbwmsgbox(par1 & par2)
End Sub

to the ExecScript shell command (.NET API):

As for vbscript, you need a launcher script; LauncherTest.vbs executes Test.vbs

the LauncherTest.vbs:

'.x64

Sub Main()
    Set pDBWInit = CreateObject("MwPDMApi.Initialize")
    Set pDBWAppl = pDBWInit.StartConnection(DBWorksApplicationName)
    myPar1 = 5
    myPar2 = 10
    pDBWAppl.CommandShell("ExecScript Test.vbs" & "&@par1=" & Chr(34) & myPar1 & Chr(34) & "\r\npar2=" & Chr(34) & myPar2 & Chr(34))
    pDBWInit.EndConnection
End Sub

please note it's mandatory to specify parameters between double quotes that are passed in vbscript as Chr(34)

The test.vbs

Sub Main()

    DBWInit(TRUE)
 dbwmsgbox(par1 & par2)
End Sub


Variant notes case

When you associate a variant note to a script, it is possible to link different subroutines rather tha the main one.

you can do it specifying the name of the subroutine during the link procedure to the variant note

In the dialog that allows you to choose what field or script has to be associated to the varian note, you've to write:

@DBW=.VBSCRIPT recall.LST&NameOfTheSubRoutine

Example

Suppose to have a script file called TestCall.LST in the DBWORKS\LST folder.

.VBSCRIPT

Sub main()
 DBWINIT(TRUE)
 DBWOutput "TEXT","MAIN PROCEDURE",ForWriting
End Sub
Sub AnotherSub()
 DBWINIT(TRUE)
 DBWOutput "TEXT","OTHER PROCEDURE",ForWriting
End Sub

 

If you do not associate any particular subroutines name to the variant note

@DBW=.VBSCRIPT recall.LST

you'll obtain the value MAIN PROCEDURE, because the Sub Main() has been executed.

 

If you associate the following code to the variant note

@DBW=.VBSCRIPT recall.LST&AnotherSub

you'll obtain the value OTHER PROCDURE because the specified sub has been executed.