GoogleDude Posted December 31, 2007 Posted December 31, 2007 (edited) Not sure why this is happening but when ever I run the app without any switches at all I get an error "Array variable has incorrect number of subscripts or subscript dimension range exceeded."What I am trying to do is make it so if a undefined switch is passed to the compiled script it displays the MSGBOX. Instead the MSGBOX ONLY apears if I type a invalid switch. If I just run the compiled or uncompiled script I get the ARRAY error from above.I am using the below codeIf Not $CMDLINE[0] And $CMDLINE[1] = '/show' or '/hide' or '/remove' Then MsgBox(1024,"Not a valid switch.","An invalid switch was passed to program.exe, Valid switches are /show /hide or /remove!") Exit EndIfI must be misunderstanding something. I did read the "Running Scripts" section in the help. But still just dont get it aparently.Many thanks,GoogleDude Edited December 31, 2007 by GoogleDude
searchresult Posted December 31, 2007 Posted December 31, 2007 try adding to do code dim $CMDLINE[2] post the whole code not the section cause it is harder to help if you post just part of the code.
MHz Posted December 31, 2007 Posted December 31, 2007 (edited) I must be misunderstanding something. I did read the "Running Scripts" section in the help. But still just dont get it aparently."If Not $CMDLINE[0] and $CMDLINE[1]" is stating that if no cmdline switch was passed but check the first parameter which leads to using $CMDLINE[1] when AutoIt has not declared the array. The logic used is flawed. Check $CMDLINE[0] and if it is not zero then you can check the other elements of $CMDLINE, but not if $CMDLINE[0] equals zero else the script will error. You need to compare the switch each time with $CMDLINE[1], so your or "this or that then" is incorrect. It needs to be or "this = that or that = this then"... This may help you If $CMDLINE[0] Then If $CMDLINE[1] <> '/show' And $CMDLINE[1] <> '/hide' And $CMDLINE[1] <> '/remove' Then MsgBox(1024,"Not a valid switch.","An invalid switch was passed to program.exe, Valid switches are /show /hide or /remove!") Exit EndIf EndIf Edit: Moved Exit within the 2nd If statement. try adding to do code dim $CMDLINE[2] post the whole code not the section cause it is harder to help if you post just part of the code.AutoIt handles the declaration so your Dim statement is not required. Edited December 31, 2007 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