Jump to content
jmp

Error: array variable has incorrect number of subscripts or subscript dimension range exceeded

Recommended Posts

Posted (edited)

Script running good but error in line 7.

When i run this script :

#include <IE.au3>
#include <Array.au3>
$oIE = _IEAttach ("Shop")
$oTable = _IETableGetCollection ($oIE, 1)
$aTableData = _IETableWriteToArray ($oTable)
For $inumber = 1 To UBound($aTableData) -1
    $table = $aTableData[4][$inumber]
    MsgBox(0, "", $table)
Next

I got Error: array variable has incorrect number of subscripts or subscript dimension range exceeded

Edited by jmp
added -1 after ubond

Share this post


Link to post
Share on other sites

Without having had a close look it is 99.99999% of the time that it is a zero based array and the Ubound() returns the number of items, so the last item is the Ubound() value-1.

Jos

Share this post


Link to post
Share on other sites
1 minute ago, Jos said:

Without having had a close look it is 99.99999% of the time that it is a zero based array and the Ubound() returns the number of items, so the last item is the Ubound() value-1.

Jos

@Jos I added -1 after Ubond, But getting same error

Share this post


Link to post
Share on other sites

Then the other option could be that the  _IETableWriteToArray ($oTable) statement is failing to create the array and you aren't testing for it's success.
Add some error checking and debugging to your code and you will find the issue. ;) 

Jos

Share this post


Link to post
Share on other sites
6 minutes ago, jmp said:

$table = $aTableData[4][$inumber]

Maybe you are confusing rows and columns?
Reverse the 4 with $inumber, and see what happen, and, as @Jos suggested, do some error checking (an _ArrayDisplay too) :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Just now, FrancescoDiMuro said:

Maybe you are confusing rows and columns?
Reverse the 4 with $inumber, and see what happen, and, as @Jos suggested, do some error checking (an _ArrayDisplay too) :)

@FrancescoDiMuro After Reverse the 4 with $inumber i am not getting any error, But i want to read all column of fourth row.

Share this post


Link to post
Share on other sites

@jmp
So you have to use the flag $UBOUND_COLUMNS in the UBound() function in your For loop, or it will go from the first row to the latest, and not the column :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


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

@jmp
So you have to use the flag $UBOUND_COLUMNS in the UBound() function in your For loop, or it will go from the first row to the latest, and not the column :)

@FrancescoDiMuro Added, But getting same error

#include <IE.au3>
#include <Array.au3>
$oIE = _IEAttach ("Shop")
$oTable = _IETableGetCollection ($oIE, 1)
$aTableData = _IETableWriteToArray ($oTable)
For $inumber = 1 To UBound($aTableData, $UBOUND_COLUMNS) -1
    $table = $aTableData[4][$inumber]
    MsgBox(0, "", $table)
Next

 

Share this post


Link to post
Share on other sites

@jmp

Quote

as @Jos suggested, do some error checking (an _ArrayDisplay too) :)

 


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

@FrancescoDiMuro, @Jos

i am asking here another question.

How can i find smallest/highest number from this

#include <IE.au3>
#include <Array.au3>
$oIE = _IEAttach ("Shop")
$oTable = _IETableGetCollection ($oIE, 1)
$aTableData = _IETableWriteToArray ($oTable)
For $inumber = 1 To UBound($aTableData, 0)
    $table = $aTableData[4][$inumber]
    $iTwo = StringLeft ($table, 2) ; i found all number using it
    MsgBox(0, "", $iTwo)
Next

 

Share this post


Link to post
Share on other sites

0 just indicates the number of dimensions for example is it a 1d array or 2d array, you could use something like:

Switch UBound($aTableData, 0) ;~ Switch between 1d/2d arrays
    Case 1 ;~ 1d Array
        For $iRow = 0 To UBound($aTableData) - 1
            MsgBox(4096, "Item", "Row : " & $iRow & @CRLF & "Val : " & $aTableData[$iRow])
        Next
    Case 2 ;~ 2d Array
        For $iRow = 0 To UBound($aTableData) - 1
            For $iCol = 0 To UBound($aTableData, 2) - 1
                MsgBox(4096, "Item", "Row : " & $iRow & @CRLF & "Col : " & $iCol & @CRLF & "Val : " & $aTableData[$iRow][$iCol])
            Next
        Next
EndSwitch

 

Share this post


Link to post
Share on other sites
2 hours ago, jmp said:

@FrancescoDiMuro, @Jos

I added 0 after UBound($aTableData

#include <IE.au3>
#include <Array.au3>
$oIE = _IEAttach ("Shop")
$oTable = _IETableGetCollection ($oIE, 1)
$aTableData = _IETableWriteToArray ($oTable)
For $inumber = 1 To UBound($aTableData, 0)
    $table = $aTableData[4][$inumber]
    MsgBox(0, "", $table)
Next

Now i am not getting any error

@Subz 

Will there be any problem with its use ?

Share this post


Link to post
Share on other sites
45 minutes ago, Subz said:

0 just indicates the number of dimensions for example is it a 1d array or 2d array, you could use something like:

Switch UBound($aTableData, 0) ;~ Switch between 1d/2d arrays
    Case 1 ;~ 1d Array
        For $iRow = 0 To UBound($aTableData) - 1
            MsgBox(4096, "Item", "Row : " & $iRow & @CRLF & "Val : " & $aTableData[$iRow])
        Next
    Case 2 ;~ 2d Array
        For $iRow = 0 To UBound($aTableData) - 1
            For $iCol = 0 To UBound($aTableData, 2) - 1
                MsgBox(4096, "Item", "Row : " & $iRow & @CRLF & "Col : " & $iCol & @CRLF & "Val : " & $aTableData[$iRow][$iCol])
            Next
        Next
EndSwitch

 

@Subz Error: Missing separator charecter after keyword.

Share this post


Link to post
Share on other sites

Thanks @Subz

Your code is really helpful.

i am getting number using 

#include <IE.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>

$oIE = _IEAttach ("Shop")
$oTable = _IETableGetCollection ($oIE, 1)
$aTableData = _IETableWriteToArray ($oTable)
$iRow = 4
for $iCol = 1 To UBound($aTableData, 2) - 1
MsgBox(4096, "Item", "Row : " & $iRow & @CRLF & "Col : " & $iCol & @CRLF & "Val : " & Number($aTableData[$iRow][$iCol]))
Next

How can i find smallest number from it ?

Share this post


Link to post
Share on other sites

Arrays are always 0 based so Row 0 and Column 0 (only for 2d arrays) are the lowest numbers.

Share this post


Link to post
Share on other sites
3 minutes ago, Subz said:

Arrays are always 0 based so Row 0 and Column 0 (only for 2d arrays) are the lowest numbers.

@Subz You are not understand me. 

i want to find smallest number from Number($aTableData[$iRow][$iCol]))

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

    • By sksbir
      Hi
      Trying this from autoit v3.3.14.5 and SCITE 3.19.102.1901.0 :
      help file , page "Language Reference - Variables" , sample autoit script about maps:

      Maps must be declared before use by defining their scope using the 'Global/Local/Static' keywords. Local $mControls[]
      So is my test script : only with this local declation.
      -check syntax is OK
      - running script : 

      test.au3" (13) : ==> Variable subscript badly formatted.: Local $mControls[] Local $mControls[^ ERROR ->14:51:49 AutoIt3.exe ended.rc:1
      any clue ?
    • By Blitzkid
      Hello, i want to search several directories for files with the largest numbers behind them (Like "video123") . They dont have a datatype. But there are also files with longer names and datatypes in these folders (Like "video778.mp4"). Is it possible to filter the _FileListToArray Syntax from
      to smth. like
       
      Here is my Code
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> #include <File.au3> $filedir = @ScriptDir & "\" _checkfile() Func _checkfile() ConsoleWrite("______________________" & @CRLF) Local $arr[3] = ["music", "picture", "video"] For $i = 0 To UBound($arr) - 1 Local $arrayfiles = _FileListToArray($filedir & $arr[$i], $arr[$i] & "*", 1) If @error = 1 Then ConsoleWrite($arr[$i] & "Error 1") EndIf If @error = 4 Then ConsoleWrite($arr[$i] & "Error 2") ;Exit EndIf $arrayfilter = _ArrayMax($arrayfiles, 0, 1) Global $stringfiles = StringReplace($arrayfilter, $arr[$i], "") ConsoleWrite($arrayfilter & @CRLF) Next EndFunc ;==>_checkfile  
    • By nacerbaaziz
      Good morning guys, i hope that you're all well.
      guys, i have a problem and i hope that you can help me
      i've created an 3d array
      the array Contain a Categories info
      as folow
      $array[n][0][0] = Categorie name
      $array[n][0][1] = Categorie file path
      $array[n][0][2] = Categorie contents number
      $array[n][m][0] = link name
      $array[n][m][1] = link url
      $array[n][m][2] = link section name
      in my tool i want to add an option to delete a Category
      as you know the Categorie mean that must delete a region from the array
      when i tried to use _arrayDelete
      with the 2d array it work well
      but here i couldn't find any way to do that, can any one help me please?
      thanks in advance.
    • By nacerbaaziz
      hello sirs, please help me
      i tried to create a function that read a folder files to 3d array
      e.g
      $array[n][0][0] = ctName
      $array[n][0][1] = ctFilePath
      $array[n][0][2] = crtsections number
      $array[n][m][0] = KeyName
      $array[n][m][1] = KeyVal
      $array[n][m][2] = keySectionName
       
      that the array
      when i put one file into the folder all things work fine
      but when i put more than one file
      the last file worked fine but the others only the first key is showing
      please can you help me to correct this problem
      here is the example with the folder
      please accept my greetings
      and thanks in advance
       
      array3d.zip
    • By nacerbaaziz
      good morning everybody.
      today i liked to share an small example with you
      which it an function to read the registry values as an array
      the result array is 2d array witch
      $a_array[n][0] = value name
      $a_array[n][1] = value Data
      $a_array[0][0] = values count
      here's the function

      #include <Array.au3> #include <WinAPIReg.au3> #include <APIRegConstants.au3> Local $a_array = _RegReadToArray("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run") If @error Then     MsgBox(16, "error", @error)     Exit EndIf _ArrayDisplay($a_array) Func _RegReadToArray($s_RegKey)     Local $a_KeySplitInfo = StringSplit($s_RegKey, "\\", 2)     If UBound($a_KeySplitInfo) <= 1 Then         $a_KeySplitInfo = StringSplit($s_RegKey, "\", 2)         If UBound($a_KeySplitInfo) <= 1 Then Return (1, 1, 0)     EndIf     Local $H_KeyInfo = "", $s_RegKeyInfo = ""     Switch $a_KeySplitInfo[0]         Case "hklm", "HKEY_LOCAL_MACHINE", "hklm64", "HKEY_LOCAL_MACHINE64"             $H_KeyInfo = $HKEY_LOCAL_MACHINE         Case "hkCu", "HKEY_CURRENT_USER", "hkCU64", "HKEY_CURRENT_USER64"             $H_KeyInfo = $HKEY_CURRENT_USER         Case "hkCr", "HKEY_CLASSES_ROOT", "HKCR64", "HKEY_CLASSES_ROOT64"             $H_KeyInfo = $HKEY_CLASSES_ROOT         Case "HKU", "HKEY_USERS", "HKU64", "HKEY_USERS64"             $H_KeyInfo = $HKEY_USERS         Case Else             Return SetError(2, 2, 0)     EndSwitch     _ArrayDelete($a_KeySplitInfo, 0)     $s_RegKeyInfo = _ArrayToString($a_KeySplitInfo, "\")     Local $H_KeyInfoOpen = _WinAPI_RegOpenKey($H_KeyInfo, $s_RegKeyInfo, $KEY_READ)     Local $A_KeyInfo = _WinAPI_RegQueryInfoKey($H_KeyInfoOpen)     If @error Then Return SetError(1, 1, 0)     _WinAPI_RegCloseKey($H_KeyInfoOpen)     Local $A_RegVal[$A_KeyInfo[2] + 1][2]     Local $iV = 1, $s_RegRead = ""     While 1         $s_RegVal = RegEnumVal($s_RegKey, $iV)         If @error <> 0 Then ExitLoop         $s_RegRead = RegRead($s_RegKey, $s_RegVal)         If Not (@error) Then             $A_RegVal[$iV][0] = $s_RegVal             $A_RegVal[$iV][1] = $s_RegRead         EndIf         $iV += 1     WEnd     $A_RegVal[0][0] = UBound($A_RegVal) - 1     If $A_RegVal[0][0] >= 1 Then         Return $A_RegVal     Else         Return SetError(3, 3, 0)     EndIf EndFunc   ;==>_RegReadToArray
      i hope you benefit from it
      with my greetings
×
×
  • Create New...