I want to test if a specific named argument has been provided before validating that argument, so I can provide meaningful error codes for missing and invalid conditions. I have this now
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colArgs = WScript.Arguments.Named
If colArgs.Item("Script") Then
If not objFSO.FileExists(colArgs.Item("Script")) Then
intReturn = 1805
End If
Else
intReturn = 1639
End If
If Not intReturn Then
msgBox colArgs.Item("Script"), 0, "Script"
Else
msgBox intReturn, 0, "Error"
End If
And my expectation would be that if I don't provide an argument called Script at all, I would get the Error msgBox with the 1639 value. Instead I get the good msgBox, with a blank for Script. I also tried
If Not colArgs.Item("Script") = "" Then
EDIT: Per @Tomalak, I now have this
Option Explicit
Dim objShell, objFSO, colArgs, intReturn
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colArgs = WScript.Arguments.Named
If Not IsEmpty(colArgs.Item("Script")) Then
If Not objFSO.FileExists(colArgs.Item("Script")) Then
intReturn = 1805
End If
Else
intReturn = 1639
End If
If IsEmpty(intReturn) Then
msgBox colArgs.Item("Script"), 0, "Script"
Else
msgBox intReturn, 0, "Error"
End If
And for what it is worth, I am calling the VBScript from PowerShell like this
$script = "\\Mac\iCloud Drive\Px Tools\Dev 4.0\#Spikes\Helper\Helper Target.ps1"
$arguments ="`"\\Mac\iCloud Drive\Px Tools\Dev 4.0\#Spikes\Helper\PxHelper.vbs`" //nologo /script:`"$script`" /wait:1"
Start-Process -filePath:Wscript.exe -argumentList:$arguments
And now I get the error condition even when the script IS provided. Grrr, Mondays.