RyukShini

Array variable has incorrect number of subscripts

11 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
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

 

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Edited by Jfish

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

Share this post


Link to post
Share on other sites

@RyukShini

And on which line of code do you get that error?
The code in your first post seems correct (although not full)

Share this post


Link to post
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 ;)
 

Share this post


Link to post
Share on other sites
7 minutes ago, Jfish said:

Ah, okay glad it is working but next time please include a full reproducer.  That IF statement would have been good info ...

Alright sorry about that. ;)

Share this post


Link to post
Share on other sites

If you dont specify any flags to _FileReadToArray(), it will store the array count on index 0 by default.

For $i = 1 to $okay[0]
    $Read = $okay[$i]
Next

 


---------Arthur B

Share this post


Link to post
Share on other sites
2 minutes ago, Bucione said:

If you dont specify any flags to _FileReadToArray(), it will store the array count on index 0 by default.

For $i = 1 to $okay[0]
    $Read = $okay[$i]
Next

 

Alright thank you for making that clear.

Share this post


Link to post
Share on other sites

#11 ·  Posted

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

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

  • Similar Content

    • jjohn
      By jjohn
      Hi all,
      I have the following code, basically, it populates an array with unique characters found in a string, but it turns out only one character is in the array, i don't want to think it is due to a bug of autoit at this point, so i need your help on why, please
      Dim $sx[0] Dim $cn $ss = "Xx" ConsoleWrite(StringLeft($ss, 1) & " " & StringRight($ss, 1) & @CRLF) ConsoleWrite(StringLeft($ss, 1) = StringRight($ss, 1) & @CRLF) ;here show X <> x ConsoleWrite(@CRLF) ;the following is to populate array $sx with different unique characters in $ss For $b = 1 To StringLen($ss) $flg = 0 For $a = 0 To UBound($sx) - 1 ;if asc(StringMid($ss,$b,1)) = asc($sx[$a]) Then ;if this line is used instead of the next, everything is fine If StringMid($ss, $b, 1) = $sx[$a] Then If StringMid($ss, $b, 1) = "x" Then ConsoleWrite("<<->>" & StringMid($ss, $b, 1) & " " & $sx[$a] & @CRLF) $flg = 1 ExitLoop EndIf Next If $flg = 0 Then $cn = $cn + 1 ReDim $sx[$cn] $sx[$cn - 1] = StringMid($ss, $b, 1) EndIf Next ConsoleWrite(UBound($sx) & @CRLF);list the ubound of $sx ;list what is in array $sx For $a = 0 To UBound($sx) - 1 ConsoleWrite($sx[$a] & @CRLF) Next same code in a file is attached as uniqueChar2Array.au3
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening
      I was looking around the forum if I could find a function that allows to convert a string into a 2 dimensional array...
      The first column of the array is always the same, but the rows could change...
      I have a pattern like:

      Column A|Column B
      Static Text 1|Data 1
      Static Text 2|Data 2
      Static Text 3|Data 3
      Static Text 4|Data 4

      Where, Static Text (1...4) will be always the same, and I don't want to change them... But, Data 1...4 are dynamic fields... So, I could have the pattern above AND I coould have the pattern I'm going to show you right below

      Column A|Column B
      Static Text 1|Data 1
      Static Text 2|Data 2
      Static Text 3|Data 3
      Static Text 4|Data 4
      Static Text 1|Data 5
      Static Text 2|Data 6
      Static Text 3|Data 7
      Static Text 4|Data 8

      How can I do in this case?

      Thanks for everyone's help


       
    • ur
      By ur
      I have a string with comma seperated as below.
      Name="Test-win10x64,Test-win10x65,Test-win10x67"
      $machine_names = StringSplit($tempINIValue, ',', $STR_ENTIRESPLIT) with the above line i can get a single dimension array.
      But I want a tabular format array like 4X4 where I want to add the 4 single dimension arrays as different columns in them.
       
      Is there any option to do the same.
    • 232showtime
      By 232showtime
      im getting strange output in array display,$split_[1] is not properly aligned to other arrays and why guictrlsetdata is not writting any data if i put comma(,) at the end of the text in $Input1???
       
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #Region ### START Koda GUI section ### Form=C:\Users\user\Desktop\Script\StringSplit.kxf $Form1 = GUICreate("Form1", 623, 449, 192, 114) $Input1 = GUICtrlCreateInput("50UGITQ421X, 50UGITQ422X, 50UGITQ423X, 50UGITQ427X, 50UGITQ431X, 50UGITQ435X, 50UGITQ436X, 50UGITQ437X, 50UGITQ441X, 50UGITQ445X, 50UGITQ449X, 50UGITQ453X, 50UGITQ454X, 50UGITQ455X, 50UGITQ459X", 24, 16, 553, 21) $Split = GUICtrlCreateButton("Split", 24, 48, 75, 25) $List1 = GUICtrlCreateList("", 24, 96, 553, 97) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Split $read = GUICtrlRead($Input1) $split_ = StringSplit($read, ",") $Max = UBound($split_, 1) For $i = 1 To UBound($split_) - 1 ConsoleWrite($split_[$i] & @CRLF) ;~ ControlSetText($Form1, "", $List1, $split_[$i]) GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $i) Next _ArrayDisplay($split_) EndSwitch WEnd  
    • hcI
      By hcI
      Hey !
      I was looking for an array display to see the result of StringSplit but when i called the <Array.au3>, an error is showing up when i try to launch the script.
      I took a screenshoot of the windows dialog box error : imp.bmp
      And when I look into the Array.au3 there is no error :
      Why is it doing this ?