Jump to content

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


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

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

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

 

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

 

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

 

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 ?

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.

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 ?

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]))

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By TheAlienDoctor
      Hi, I was looking into creating a script that would detect if a file exists, then move it (and in some cases rename it, depending on the file) as well as write to a log file.
      The issue is, there is a lot of files that need to be moved, sometimes some files will exist and others won't depending on the use-case. However if a file does exist, it will always be going into the same directory with the same name.
      Currently I have an array nested inside of the array, with each array inside that array having both the old and new directory, and then a For loop to actually run through and do the file transferring. The issue I am having is how to call the Array inside of the array, because how do I specify  which the old directory is and which the new is?
      Global $FileTransfer[2000] = [Global $Dir1[2] = ["original dir 1", "new dir 1"], Global $Dir2[2] = ["original dir 2", "new dir 2"]] For $FileTransfer = [0] To [1] Step +1 If FileExists({original dir}) Then FileMove({original dir}, new dir, 1) FileOpen("log.latest.txt", 1) FileWrite("log.latest.txt", "{original dir} found, moved it to new dir." & @CRLF) FileClose("log.latest.txt") Else FileOpen("log_latest.txt", 1) FileWrite("log_latest.txt", "{original dir} not found, ignoreing it." & @CRLF) FileClose("log_latest.txt") EndIf Next I have put what I want the old and new directory to be for each array in {}, so hopefully its easier to tell which part is working and whats not.

      I am still reasonably new to AutoIT, any help is appreciated. Thankyou
    • By arunkw
      I have a spreadsheet - daily routine which has two columns: activity and time as shown here
      | Activity             | Time     | |----------------------|----------| | Sleep               |  6:00 am | | Toilet              |  6:15 am | | Get ready for gym  |  6:30 am | | Exercise            |  7:50 am | | ... more things      |  9:00 pm | | ... still more       | 10:45 pm | | Sleep               |  6:00 am |   I wanted to find out, say in C1 which activity is current for me using now() I.e., if it’s 6:45am on my watch, it should show me Exercise  in C1 Thanks to Adam D. PE, this formula works like magic to get the result =VLOOKUP(MOD(NOW(),1),{B2:B,A2:A},2,1)   Now, I want to reproduce same result in autoit, how to do that? To have easy solution say, I copy-paste spreadsheet data in array directly in code, right? Use for loop and run the above vlookup function and show the answer using tooltip. How to achieve this? please help.  
    • By goku200
      I have an Autoit script that lists files from a folder into an array list. Is there a way to separate the filenames by an underscore and include the id, version, name and date into separate columns in Excel.
      Example of filename:
      12345_v1.0_TEST Name [12345]_01.01.2022.html
      12345 would be in one column
      v1.0 would be in another column
      TEST Name [12345] would be in another column
      01.01.2022 would be in another column
      .html would be in another column
      Note: filenames always change each day.
      Here is my code that lists the files into column C and then writes the column Headers into Column D, E, F, G. Just need some help with separating them into columns by the _ delimiter
       
    • By mLipok
      Usually when I collect data from DataBase I need to give EndUser a possibility to select rows which should be taken in the processing loop.
      I was searching on the forum and I'm not able to find any UDF or even example of how to select data from array.
      I have my own solutions but I think they are not worth posting on the forum as it is very old code and I am looking for a better solution.

      Could anybody point me to some examples/solutions ?

      Thank you in advance.
      @mLipok
    • By EmilyLove
      I have a string containing the full path of an executable and an array of executables without their paths. I am trying to compare the string to the list in the array and if a match is found, remove it from the array. The entry get removed from the array successfully, and after checking its return result, uses it to update the ubound if it succeeded, but it doesn't want to update to the new value. Any ideas what I am doing wrong? It acts like it is read-only.
      #include <Array.au3> #include <File.au3> Local $sApp_Exe = "F:\App\Nextcloud\nextcloud.exe" Local $aWaitForEXEX = [3, "Nextcloud.exe", "nextcloudcmd.exe", "QtWebEngineProcess.exe"] For $h = 1 To $aWaitForEXEX[0] If StringInStr($sApp_Exe, $aWaitForEXEX[$h]) <> 0 Then $iRet = _ArrayDelete($aWaitForEXEX, $h) If $iRet <> -1 Then $aWaitForEXEX[0] = $iRet ;this line doesn't work. $aWaitForEXEX[0] doesn't update and shortly gives Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.: _ArrayDisplay($aWaitForEXEX) EndIf Next  
×
×
  • Create New...