Jump to content

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


jmp
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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.

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

 

Link to comment
Share on other sites

@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

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

 

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

 

Link to comment
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 ?

Link to comment
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.

Link to comment
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 ?

Link to comment
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]))

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...