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

    • dexto
      By dexto
      Why idea why would I get an error (Autoit Beta 3.3.15.0):
      Local $json[] Local $map[] $map['test'] = 'hello' Local $array[5] = [1, 2, 3, 4, 5] $json["data"] = $map $json["data"]["arr"] = $array ConsoleWrite($json["data"]["arr"][0] & @CRLF)  
    • cookiemonster
      By cookiemonster
      Im trying to read a JSON file into an array.
       
      The JSON looks like this:
       
      { "project_info": { "project_number": "123456789", "url": "https://www.website.com", "project_id": "PRJ08", "Bucket": "Buk09" }, "client": [ { "client_info": { "id": "1:1001306455", "info": { "name": "banana" } }, "oauth_client": [ { "client_id": "1001306455694-m3h6v", "client_type": 3 } ], "a_key": [ { "key": "dkldkdkd" } ], "Avail": { "ana": { "status": 1 }, "vit": { "status": 1, "other": [] }, "ad": { "status": 2 } } }, { "client_info": { "id": "1:1838346", "info": { "name": "orange" } }, "oauth_client": [ { "client_id": "2145696315633-dmdhe", "client_type": 3 } ], "a_key": [ { "key": "osikdme" } ], "Avail": { "ana": { "status": 1 }, "vit": { "status": 1, "other": [] }, "ad": { "status": 2 } } }, ], "configuration_version": "1" } What I want to do is read it all into one single large array, can anyone help? 
      All I have so far is:
      #include "JSON.au3" #include "array.au3" $file = fileread("C:\file.json") JsonToArray($file) Func JsonToArray($JSON) $JSON = StringRegExpReplace($JSON, "[\[\]{}]", "") $sBreak = StringSplit($JSON, ",") For $a = 1 To $sBreak[0] $t = _JSONDecode("{" & $sBreak[$a] & "}") _ArrayDisplay($t, "multi " & $a & " of " & $sBreak[0]) Next EndFunc ;==>JsonToArray  
    • SkysLastChance
      By SkysLastChance
      I was wondering if it is possible to make this code skip to the next row if it reads a blank line?
      I tried this.
      If $aArray = "" Then $r += 1 EndIf #include <Excel.au3> Local $r = 1 Local $aArray = _Excel_RangeRead($oWorkbook) ;~ If $iBox is greater than no. of rows in $aArray then $iBox equals the number of rows in $aArray If $iBox > (UBound($aArray) - 1) Then $iBox = UBound($aArray) - 1 For $i = 1 To UBound($aArray) - 1 ;$i =0 Start from row A If $aArray = "" Then $r += 1 EndIf $sR0 = $aArray[$i][0] ;status $sR1 = $aArray[$i][1] ;first name $sR2 = $aArray[$i][2] ;Last name $sR3 = $aArray[$i][3] ;Last 4 SSN $sR4 = $aArray[$i][4] ;DOB $sR5 = $aArray[$i][5] ;Email Address $sR6 = $aArray[$i][6] ;Mailling Address $sR7 = $aArray[$i][7] ;City $sR8 = $aArray[$i][8] ;state $sR9 = $aArray[$i][9] ;Zip Code $sR10 = $aArray[$i][10] ;Gender $sR11 = $aArray[$i][11] ;Phone WinSetState ("ADM.MCK - Registration Management Desktop","",@SW_MAXIMIZE) WinWaitActive("[CLASS:Notepad]", "", 10) ControlSend("[CLASS:Notepad]", "", "", ("{F8}")) Sleep (500) ControlSend("[CLASS:Notepad]", "", "", ("{F8}")) Sleep (500) ControlSend("[CLASS:Notepad]", "", "", ("N")) ControlSend("[CLASS:Notepad]", "", "", ("{TAB}")) Sleep (3000) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR1 & @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "", ("{TAB}")) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR2 & @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "", ("{TAB}")) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR6& @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "", ("{TAB}")) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR7 & @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR8 & @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR9 & @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR11& @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR5 & @CR) ;Email Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR5 & @CR) ;Email Sleep (200) ControlSend("[CLASS:Notepad]", "", "", (FormatDate($sR4) & @CR)) $r += 1  
       
    • nss
      By nss
      Hi all.
       
      Because of me wondering if I could access the key/value pair arrays with the numbers as indexes, I have found out that the zeroth element for some reason doesn't return anything.
      Here's the example:
       
      local $r[2] $r["test1"]="hello" $r["test2"]="how are you" msgbox(64, $r[0], $r[1]) ; prints the ["test2"] but not ["test1"]. Is this even supposed to be a thing?  
       
      BTW, I haven't seen Autoit get updated since 2015; is it abandened or something?
      Any help/clarification appreciated.
    • Starf0x
      By Starf0x
      Hi,
       
      I'm a bit stuck (my brains might be hanging in a loop).
      Here's my dillema, what if there is no command line parameters are given?
       
      Global $aCmdLine = _WinAPI_CommandLineToArgv($CmdLineRaw) I've tried this, and more:
      If UBound($aCmdLine) - 1 < 1 Then ConsoleWriteError(@CRLF & "For more information use: " & @ScriptName & " /?" & @CRLF) Exit EndIf This works, the program doesn't continue, but doesn't show the ConsoleWrite, I've tried sleeps etc...
      Cheers, Starf0x