Jump to content

cmdline issue (is it just me or is it a bug?)


Recommended Posts

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
Link to comment
Share on other sites

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 by Jango
Link to comment
Share on other sites

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 by MHz
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...