Return to Snippet

Revision: 7863
at August 18, 2008 13:54 by ScryptKeeper


Initial Code
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

Initial URL


Initial Description


Initial Title
Parse Command Line Parameters (VBScript)

Initial Tags
windows

Initial Language
Visual Basic