Jump to content
Sign in to follow this  

UDF: _ParameterGetValue

Recommended Posts


If you're someone who likes to use command-line parameters, you'll probably appreciate this UDF. It checks the command line parameters, trying to determine the value of a parameter. For example:

If you have on the command line "/user ItsMe! /password NeverGuess", you could do this:


and it would return 'ItsMe!'

It also works for:




but is smart enough to avoid this:

'/user /password NeverGuess'

You can pass your own switch prefix, so these work too:

'-user ItsMe!'


Here's the code:


Func _ParameterGetValue($Switch, $SwitchPrefix = '/', $CaseSense = 0)

Dim $i, $num = $CmdLine[0], $Sw = $SwitchPrefix & $Switch, $SwLen = StringLen($Sw), $Return = ''

;First, look for the switch

While $num > 0

If $CaseSense Then

If StringLeft($CmdLine[$num], $SwLen) == $Sw Then ExitLoop


If StringLeft($CmdLine[$num], $SwLen) = $Sw Then ExitLoop


$num = $num - 1


If $Num > 0 Then

;First check for '/Switch=Value' situation

$i = _StringInChr($CmdLine[$num], ':=,')

If $i <> 0 Then

$Return = StringMid($CmdLine[$num], $i + 1)

;Next check for '/SwitchValue' situation

ElseIf StringLen($CmdLine[$num]) > $SwLen Then

$Return = StringMid($CmdLine[$num], $SwLen + 1)

;Next check for '/Switch Value' situation

ElseIf $num + 1 > $CmdLine[0] Then

; there is no value (there is no next parameter)

$Return = ''

ElseIf _StringInChr(StringLeft($CmdLine[$num + 1], 1), $SwitchPrefix) Then

;this must be another parameter, not a value

$Return = ''


$Return = $CmdLine[$num + 1]



;No switch = error



Return $Return


And it returns with an error if the switch was not found at all, so you can also use it to detect a switch, for example if you have a switch that doesn't have a value

It does require my _StringInChr function:


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.