/ Published in: Visual Basic
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
Function CmdLineParam(AStartAt, AsingleSwitch, AMatchCase, ALongSwitch, AAssigned, APosition, AFollowing)
' AStartAt Which argument position to start at (Zero based).
' ASingleSwitch single character param char. -a -A
' AMatchCase singleSwitch should be came case for a match
' ALongSwitch Long Switch value that is preceed by --. i.e. --test --file=
' AAssigned Everything following the single switch char, or everything after = in a LongSwitch
' APosition Which value on the command line this matched
' AFollowing Value of next parameter on the command line
' Returns true if the parameter was found
Dim Found
Dim c1
Dim count
Dim args
Dim ASign
Set args = WScript.Arguments
Found = False
c1 = AStartAt
count = args.count
While Not found And c1 < count
If (Left(args(c1),2)) = "--" Then
If UCase(Mid(args(c1),3,Len(ALongSwitch))) = (UCase(ALongSwitch)) Then
Found = True
ASign = InStr(args(c1),"=")
If ASign <> 0 Then
AAssigned = Mid(args(c1),ASign+1,Len(args(c1)))
Else
AAssigned = ""
End If
End If
ElseIf (Left(args(c1),1)) = "-" Then
If AMatchCase = True Then
' make sure it matches
If Mid(args(c1),2,1) = ASingleSwitch Then
found = True
APosition = c1
AAssigned = Mid(args(c1),3,Len(args(c1)))
If (c1 < count+1) Then AFollowing = args(c1+1)
End If
Else
' we don't care about case
If UCase(Mid(args(c1),2,1)) = UCase(ASingleSwitch) Then
found = True
APosition = c1
AAssigned = Mid(args(c1),3,Len(args(c1)))
End If
End If
End If
AFollowing = ""
If Found And (c1 < count-1) Then
AFollowing = args(c1+1)
End If
c1 = c1 + 1
Wend
CmdLineParam = Found
End Function
Comments
 Subscribe to comments
                    Subscribe to comments
                
                