1 Reply Latest reply on Feb 16, 2018 6:27 PM by .-.--.--

    Processing VBScript Arguments

    .-.--.--

      I have a VBScript that can be run from either a Mentor application or the Windows environment.  The script requires a design folder name as an argument.  Within a Mentor app, the folder name is easily found, and executed using Gui.ProcessKeyin("run " & ScriptPath & " " & FolderName).  In Windows, I can either run from a command line, or drag and drop the folder onto the .vbs file (or its shortcut).  But the problem is having a consistent method for acquiring the argument.  In Windows, the argument is stored in WScript.Arguments.  In Mentor, the argument is stored in ScriptHelper.Arguments.  But, Windows does not recognize ScriptHelper, and Mentor does not recognize WScript.  So, what's the best way to reconcile this difference?  Thanks in advance.

        • 1. Re: Processing VBScript Arguments
          .-.--.--

          Ok, nevermind.  Here is my solution, albeit very quirky:

           

          Sub Main()

          On Error Resume Next

          Set Args = WScript.Arguments

          If Err Then

               Ind = 2

               Set Args = ScriptHelper.Arguments

               Err.Clear

          End If

          On Error Goto 0

          If Args.Count <> Ind + 1 Then

               MsgBox "Invalid Input"

               Exit Sub

          End If

          Arg = Args(Ind + Sgn(Ind))

          If Fso.FolderExists(Arg) = False Then

               MsgBox "Unknown Folder"

               Exit Sub

          End If

          . . .

           

          The reason why it's quirky is because WScript returns its arguments (1 in this case) in a base-zero array, while ScriptHelper (misnomer?) returns its arguments (3 in this case, including "run" and the ScriptPath) in a base-one array.  So much for consistency.