qwert Posted February 19, 2008 Share Posted February 19, 2008 I've built a script that makes a couple of Dll calls to adjust the position of an external application window. The script is called with either one, two or three parameters, depending on the exact action being requested (move or size). Also, the script can be called more than once following start up of the external application. On occasion, I get the "Line -1 ... Error: Array variable has incorrect number of subscripts " popup message. AutoIt handles the declaration so your Dim statement is not required.Based on the above statement in a post from last year, I have NOT declared the Command Line Array -- which I guess would require: dim $CMDLINE[3] -- but I'm not sure, since it's different for each call. Is it possible that the Command Line Array is being automatically dimensioned according to the first call (only) and that upon the second call, the array size is somehow "remembered" (and is sized wrong)? I do have the script check that no more than three parameters are being passed to rule out that particular possibility. Should I declare the array? Is there a downside to doing that if fewer parameters are passed? Or is there some way to trap the error condition in the script itself? -- and then display the params using _ArrayDisplay ($CmdLine). Thanks in advance for any advice. Link to comment Share on other sites More sharing options...
Aceguy Posted February 19, 2008 Share Posted February 19, 2008 sorta guessing, but at the start of your script, i would delclare the array . dim $array[50] [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
qwert Posted February 19, 2008 Author Share Posted February 19, 2008 i would declare the array . dim $array[50]Thanks for the response. Is that just to try to catch almost any eventuality? -- or is there another (known) reason? Link to comment Share on other sites More sharing options...
MHz Posted February 20, 2008 Share Posted February 20, 2008 (edited) Should I declare the array? Is there a downside to doing that if fewer parameters are passed? Or is there some way to trap the error condition in the script itself? -- and then display the params using _ArrayDisplay ($CmdLine).That quote you show looks like my works IIRC. The $CMDLINE declaration is handled by AutoIt and it is up to you to work with the elements in the array. Check if the array does exist and the the number of elements with $CMDLINE[0]. You will not get an error if your checks are correct. Example: If $CMDLINE[0] Then For $i = 1 To $CMDLINE[0] MsgBox(0x40000, 'Parameter number ' & $i & ' passed to this script', $CMDLINE[$i]) Next EndIf If $CMDLINE[0] = 1 Then MsgBox(0x40000, 'Only one parameter was passed to the script', $CMDLINE[1]) EndIf Notice that I check before using an array that may not exist. Edit: $CMDLINE[0] always does exist but further elements are conditional. Edited February 20, 2008 by MHz Link to comment Share on other sites More sharing options...
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