Jump to content

Questions about "Array Variable Error"


qwert
 Share

Recommended Posts

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

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 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...