Jump to content

Array variable has incorrect number of subscripts


Recommended Posts

Local $okay
_FileReadToArray("Okay.txt", $okay) ; read the list of names to array
For $i = 1 To UBound($okay) - 1
$Read = $okay[$i]

If I run this and it goes to the end of Okay.txt it returns an error.
"Array variable has incorrect number of subscripts or subscript dimension range exceeded.:"
so can I either exitloop if its run through the file or add some error checking that exitloop if array = empty?
Thanks in advance.

Edited by RyukShini
Link to comment
Share on other sites

You should add a line to visualize your data to make sure it contains what you think it should.  Otherwise, using ubound($array)-1 should make the loop run the correct number of times.  Try this and look at the array, does it appear as you would expect it? 

Local $usrpwd
_FileReadToArray("Okay.txt", $okay) ; read the list of names to array
_arrayDisplay($okay); visualize data
For $i = 1 To UBound($okay) - 1
$Read = $okay[$i]

I tested this version which is almost the exact same as yours.  The file contained three lines of data.  I added debugging to error check the array creation and visualize it.  It works fine.  Maybe you could post your whole code?

#include <Array.au3>
#include <File.au3>
global $okay
Local $usrpwd
$result=_FileReadToArray(@ScriptDir&"\tesfile.txt", $okay)
ConsoleWrite($result&" error: "&@error&@crlf)
_arrayDisplay($okay); visualize data
For $i = 1 To UBound($okay) - 1
$Read = $okay[$i]
ConsoleWrite($Read)
Next

 

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

6 minutes ago, Jfish said:

You should add a line to visualize your data to make sure it contains what you think it should.  Otherwise, using ubound($array)-1 should make the loop run the correct number of times.  Try this and look at the array, does it appear as you would expect it? 

Also, note the difference in starting the loop at 0 vs 1.

Local $okay
_FileReadToArray("Okay.txt", $okay) ; read the list of names to array
_arrayDisplay($okay); visualize data
For $i = 1 To UBound($okay) - 1
$Read = $okay[$i]

 

It seems to be correct?
65972e210676f85cfedd61674f5f7514.png

 

 

Link to comment
Share on other sites

6 minutes ago, Jfish said:

Yes, try running my code where I put the results to the console in the four loop.  You should see all four items from 1-4 in the console window of Scite.

Your code works, but I actually just found out why mine wasn't working.
I needed a Continueloop in my code inside an IF statement.
Now it works as intended and it continues the loop/stops correctly.
Thanks a lot for the help ;)
 

Link to comment
Share on other sites

  • 2 months later...
On 26/10/2016 at 7:01 AM, RyukShini said:

Your code works, but I actually just found out why mine wasn't working.
I needed a Continueloop in my code inside an IF statement.
Now it works as intended and it continues the loop/stops correctly.
Thanks a lot for the help ;)
 

 

it would have been nice if you post your codes that work

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

×
×
  • Create New...