Sign in to follow this  
Followers 0
RealisT

Why isn't an Array an Array?

16 posts in this topic

I'm getting the infamous error, "Subscript used with non-Array Variable."

This really IS an array, though! It is a declared, global, and sufficiently-sized two-dimensional array...

Global $trackData[99][2]

AutoIT gives an IsArray value of 0, however, for this variable!

Before I paste the whole code here, let me ask this fundamental question:

What (theoretically) would make AutoIT consider my array invalid as an array if:

1. It is Global declared

2. It is never re-declared or re-dimensioned

3. It is given good index (parameter) values, never out of range (confirmed)

???

Can I get an answer to this, based on your knowledge of the language rather than on looking at my code?

Thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

maybe the subscript number exed the number you give... if you post the script where the data of that array is filled it will help to find out what is the problem...

did you try overpass the expected number.. for ex...

Global $trackData[150][4]

only for test propouses

after you fill the data in the array do an _arraydisplay($trackData) to see the exact number of suscripts you have

Edited by monoscout999

Share this post


Link to post
Share on other sites

This works fine for me, not sure of the issue

Global $trackData[99][2]

$trackData[1][1] = 5

ConsoleWrite($trackData[1][1])

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

To answer your questions:

1. This error is with the first occurrence of any line trying to populate the array. In other words, no data yet. It is not letting me populate it (post-declaration).

2. I am not exceeding the range. Is was declared as [99][2], and the values at error-time are [1][0].

I'm just not seeing any grounds for this not to be considered a legit array. No other code between declaration & this line refer to this or any other array.

Hope that helps.

Thanks

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Are you using any StringSplits? I imagine that if you use stringsplit on a string that ins't split then $trackdata will be changed from an array.

NVM, just saw your recent post.

Edit: Besides, that couldn't be the problem anyway, I just tested.

Edited by LaCastiglione

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

No string-splits or any other operations on/with/using the array.

Also, _arraydisplay($trackData) does not work, I suspect because AutoIt does not consider this an array (hence the problem).

Oh, and this problem line of code is within a called function. The array is global, though, so it shouldn't matter. (The variable used in the array index is global, too. So no invalid values).

Edited by RealisT

Share this post


Link to post
Share on other sites

No includes using my array. Just a generic GUIConstants.au3.

Share this post


Link to post
Share on other sites

If you use the _ArrayDisplay directly after the declaration,does it show anything in it? If it does, then something further down your script is changing it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Ok you've hooked us. Post your code, lets solve the mystery :huh2:

Share this post


Link to post
Share on other sites

The code would be a major pain for y'all to run.

It creates files, opens other apps (Sony Vegas Movie, Audacity, etc.), uses paths found only on my PC, and thus would pretty much only work on my machine...once I can get it to work : )

So if I posted it, it would be for human eyes only.

The _ArrayDisplay is not an option after the problem line, since the script can't get that far. As stated, _ArrayDisplay beforehand doesn't display at all (with the Array include included, of course).

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

post the part where the array is filled with data...

¿Did you use a for next loop to fill the data in the array?

Ex

global $trackData[99][2]
for $i = 0 to ubound($trackdata) - 1
    For $z = 0 to ubound($trackdata,2) - 1
        $z += 1 
        $trackdata[$i][$z] = $z ; This will give you error
    Next
Next

global $trackData[99][2]
for $i = 0 to ubound($trackdata) - 1
    For $z = 0 to ubound($trackdata,2) ; This also will give you error
        $trackdata[$i][$z] = $z 
    Next
Next
Edited by monoscout999

Share this post


Link to post
Share on other sites

I never get errors without code. :huh2:

There could be any number of reasons why this might occur. Chances are that you have declared the array incorrectly or possibly in a way which makes it inaccessible. Sometimes fixing things like this can be as simple as swapping two lines of code to a different order. Without seeing it there is no way to tell. You should be able to trace the error using message boxes or ConsoleWrite. If your code is long and complicated then make a simple test. Declare an array and make sure it exists. Then add more code to youe script until you reproduce the same error. Undo the changes and see if it works again. That's where the problem is.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

(Monoscout999: As I stated, the array was never populated. The error is on the first line attempting to do so).

**** I FOUND THE PROBLEM ****

While there is absolutely nothing wrong with the array, there is something wrong with the doofus at the keyboard, since he apparently likes to create another variable elsewhere with the exact same name. Please don't e-slap me.

Wouldn't you think, though, that the error would occur instead at that other line, which comes first? Why not the same error there, which would have pointed out this problem very quickly, yes?

Edited by RealisT

Share this post


Link to post
Share on other sites

Lets be straight. :huh2:

If you declare an array correctly, and never modify it, only a bug can cause AutoIt to not recognize it for what it is.

Given the unlikeliness of a fundamental bug with arrays this late in the game, chances are you're re-declaring it.

Without your code its just a guessing game for us of where and how you're doing that unknowingly. ;)

Post the smallest snippet of code that can be run and reproduces your error if you want "real" help; or just do as czardas advised. :alien:

-smartee

Share this post


Link to post
Share on other sites

Ok just saw your post ;)

You were re-declaring it :huh2: I knew it!! haha

Good luck,

-smartee

Share this post


Link to post
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
Sign in to follow this  
Followers 0