le15 Posted November 3, 2006 Posted November 3, 2006 I have four parameters in command line Sometimes i didn't have need the last parameters but i am forced to enter it as blank "" How to enter sometimes just 3 and others times 4 ?
Fossil Rock Posted November 3, 2006 Posted November 3, 2006 if the parameter is optional and you do not want to exercise your option with one of the optional parameters then use double quotes ( "" ) to nullify that parameter in the option. Agreement is not necessary - thinking for one's self is!
cppman Posted November 3, 2006 Posted November 3, 2006 Are you talking about Function parameters? if so: Func _MyFunction($RequiredParam, $NotRequired = "") ;Do something! EndFunc Miva OS Project
jpm Posted November 4, 2006 Posted November 4, 2006 I have four parameters in command line Sometimes i didn't have need the last parameters but i am forced to enter it as blank "" How to enter sometimes just 3 and others times 4 ?$cmdline[0] give you the number of passed parameters so you can check you get o,ly 3 and do what you want
Rick Posted November 4, 2006 Posted November 4, 2006 (edited) Another way is to use $Cmdlineraw and strip out the bits...... ie $Docopy = "Yes" $DontDoIt="No" $RenameDir="Yes" $Raw=StringReplace($Cmdlineraw,@ScriptFullPath,"") ; take out @ScriptFullPath if stringinstr($Raw,"No") then $Docopy = "No" if stringinstr($Raw,"Yes") then $Docopy = "Yes" if stringinstr($Raw,"DontDoIt") then $DontDoIt = "Yes" if stringinstr($Raw,"NoRename") then $RenameDir = "No" ;if $Docopy = ....... This way it doesnt matter what order the $cmdline parameters are in, providing of course that each parameter is unique. Hope this helps. Edited November 4, 2006 by Rick Who needs puzzles when we have AutoIt!!
Qsr Nrwn Posted November 7, 2006 Posted November 7, 2006 Hi, this might help, but... it is untested (a cyber quick-code), I will come with a more detailed, general-use function in a couple of days (I hope ): Func ParseCommandLineParameters() Local $i For $i =1 to $CmdLine[0] step 1 select case "/option1" ; and you can, of course nest some functions, selects, switches and so on, to handle your parameters... ; I usually use the OnEvent Mode (failed to understand the basics of MessageLoop Mode) case "/option2" case else endselect Next EndFunc Rev 127 Et factum et prælium magnum in cælo: Michaël et angeli ejus præliabantur cum dracone, et draco pugnabat, et angeli ejus: 8 et non valuerant, neque locus inventus est eorum amplius in cælo.9 Et projectus est draco ille magnus, serpens antiquus, qui vocatur diabolus, et Satanas, qui seducit universum orbem: et projectus est in terram, et angeli ejus cum illo missi sunt.
Qsr Nrwn Posted November 7, 2006 Posted November 7, 2006 There is all the code... hope it helps; yesterday's was a one-minute code... It's so buggy (This one is more tested) expandcollapse popupFunc ParseCommandLineParameters() Local $i ;~ first check if it has parameters If $CmdLine[0] = 0 Then ;~ here goes the code to handle if it have no parameters ;~ e. g.: MsgBox(0, "Error", "No parameters set...") Else ;~ if it have one or more than one parameter ;~ this does not check for duplicated parameters, as I do not want to impose that constrain For $i = 1 To $CmdLine[0] Step 1 ;~ just cycle through the array passed until it reach the last item Select Case $CmdLine[$i] = "/make" ;~ you may want to check if the next parameter is properly supplied (in context, as in /make /file=""mifile.txt) ;~ not allowing to perform some code if certain sequence of parameters is not set ;~ imagine... /delete /all-files parsed in sequence and not in sequence... the latter does not make any sense ;~ as it loses its context ;~ just remember to add one to the iterator to point to it ;~ and check if it is not out of bounds in the upper limit ;~ otherwise, just exit your loop or manage this error ;~ repeat this step for every level you go up $i = $i + 1 If $i > $CmdLine[0] Then ConsoleWrite("Error.... out of bonds") ExitLoop EndIf Select Case $CmdLine[$i] = "/american-coffee" ConsoleWrite("American coffee") Case $CmdLine[$i] = "/english-tea" ConsoleWrite("ISO standard cup of tea") Case Else MsgBox(0, "cannot make", "Did you have something to make?") EndSelect Case $CmdLine[$i] = "/boil" $i = $i + 1 If $i > $CmdLine[0] Then ConsoleWrite("Error.... out of bonds") ExitLoop EndIf Select Case $CmdLine[$i] = "/milk" Case $CmdLine[$i] = "/water" Case $CmdLine[$i] = "/alcohol" EndSelect Case $CmdLine[$i] = "/bake" EndSelect ;~ ConsoleWrite("nothing specified") Next ;~ here goes the code to handle if no match have been found ;~ here goes the code to handle if no match have been found ;~ here goes the code to handle if no match have been found ;~ here goes the code to handle if no match have been found EndIf EndFunc ;==>ParseCommandLineParameters Rev 127 Et factum et prælium magnum in cælo: Michaël et angeli ejus præliabantur cum dracone, et draco pugnabat, et angeli ejus: 8 et non valuerant, neque locus inventus est eorum amplius in cælo.9 Et projectus est draco ille magnus, serpens antiquus, qui vocatur diabolus, et Satanas, qui seducit universum orbem: et projectus est in terram, et angeli ejus cum illo missi sunt.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now