boomingranny Posted February 11, 2008 Posted February 11, 2008 What would you expect the code below to do? If $CmdLine[$CmdLine[0]] = "inevertypedthis" Then MsgBox (0, "wtf","wtf") EndIf because it is showing the msgbox... am i doing something wrong?!
boomingranny Posted February 11, 2008 Author Posted February 11, 2008 ahh, nm i think it is converting the text to a number... still confusing though...
picaxe Posted February 11, 2008 Posted February 11, 2008 If a string is used as a number, an implicit call to Number() function is done. So if it doesn't contain a valid number, it will be assumed to equal 0.In your example $CmdLine[0] is 0. However using == comparison gives proper result. If $CmdLine[$CmdLine[0]] == "inevertypedthis" Then MsgBox (0, "wtf","wtf") EndIf
Jango Posted February 11, 2008 Posted February 11, 2008 (edited) In your example $CmdLine[0] is 0. However using == comparison gives proper result. If $CmdLine[$CmdLine[0]] == "inevertypedthis" Then MsgBox (0, "wtf","wtf") EndIf Correct in fact: $CmdLine[0] is number of parameters $CmdLine[1] is param 1 (after the script name) $CmdLine[2] is param 2 etc ... $CmdLine[$CmdLine[0]] is one way to get the last parameter... So if your script is run like this: AutoIt3.exe myscript.au3 param1 "this is another param" $CmdLine[0] equals... 2 $CmdLine[1] equals... param1 $CmdLine[2] equals... this is another param Edited February 11, 2008 by Jango
MHz Posted February 11, 2008 Posted February 11, 2008 (edited) Poor logic and the idea of using "==" does nothing to improve it sorry to say. If "$CMDLINE[$CMDLINE[0]]" equates to "$CMDLINE[0]" then any comparison to the string is flawed as "$CMDLINE[0]" contains a number. Using "==" is forcing case sensitivity between strings thus is not a solution. This is what I would do in such a case accepting you actually want the last parameter if any were passed. If $CMDLINE[0] And $CMDLINE[$CMDLINE[0]] = "inevertypedthis" Then MsgBox (0, "wtf","wtf") EndIf Now you know that you are not comparing a string with "$CMDLINE[0]" as it cannot happen. Edited February 11, 2008 by MHz
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