Jump to content

Error accessing 2D array


Mateo
 Share

Recommended Posts

Hi,

I try to access a 2d array and I fail, it always throws me an error, no matter what I tried.

Can anyone help me with this?

(The code is attached, and below it the error obtained)

 

#include <Array.au3>

Dim $aPrograms
Local $aWinList = WinList()
For $i = 1 To $aWinList[0][0]
   If $aWinList[$i][0] <> "" And BitAND(WinGetState($aWinList[$i][1]), 2) Then

      If IsArray($aPrograms) = 1 Then
         ReDim $aPrograms[UBound($aPrograms)]
         Local $tempArray[2] = [$aWinList[$i][0], $aWinList[$i][1]]
         _ArrayAdd($aPrograms, $tempArray, 0, "|", @CRLF, 1)
      Else
         Dim $aPrograms[1]
         Dim $aPrograms[1][2]
         $aPrograms[0][0] = $aWinList[$i][0]
         $aPrograms[0][1] = $aWinList[$i][1]
      EndIf
   EndIf
Next
_ArrayDelete($aPrograms, 0)
_ArrayDisplay($aPrograms[0])
MsgBox(0, "", $aPrograms[0][0])
"C:\Users\Mateo\Documents\AutoIt\temp.au3" (23) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
MsgBox(0, "", $aPrograms[0][0])
MsgBox(0, "", ^ ERROR

 

Link to comment
Share on other sites

#include <Array.au3>

Dim $aPrograms
Local $aWinList = WinList()
For $i = 1 To $aWinList[0][0]
   If $aWinList[$i][0] <> "" And BitAND(WinGetState($aWinList[$i][1]), 2) Then

      If IsArray($aPrograms) = 1 Then
         ReDim $aPrograms[UBound($aPrograms)+1]
         Dim $aPrograms[UBound($aPrograms)][2]

         $aPrograms[UBound($aPrograms)][0] = $aWinList[$i][0]
         $aPrograms[UBound($aPrograms)][1] = $aWinList[$i][1]
      Else
         Dim $aPrograms[1]
         Dim $aPrograms[1][2]
         $aPrograms[0][0] = $aWinList[$i][0]
         $aPrograms[0][1] = $aWinList[$i][1]
      EndIf
   EndIf
Next
_ArrayDelete($aPrograms, 0)
_ArrayDisplay($aPrograms[0])
MsgBox(0, "", UBound($aPrograms, 2))

It should be noted that I also tried this code, but then it gets stuck in the data entry ...

Edited by Mateo
Link to comment
Share on other sites

Here how you would do it :

#include <Array.au3>

Local $aPrograms[0][2]
Local $aWinList = WinList()
For $i = 1 To $aWinList[0][0]
  If $aWinList[$i][0] <> "" And BitAND(WinGetState($aWinList[$i][1]), 2) Then
    ReDim $aPrograms[UBound($aPrograms) + 1][2]
    $aPrograms[UBound($aPrograms)-1][0] = $aWinList[$i][0]
    $aPrograms[UBound($aPrograms)-1][1] = $aWinList[$i][1]
  EndIf
Next
_ArrayDisplay($aPrograms)
MsgBox(0, "", UBound($aPrograms))

 

Link to comment
Share on other sites

Just in case you prefer a solution with _ArrayAdd (actually superfluous after @Nine presented his one ;)).

#include <Array.au3>
Local $aPrograms[0][2]
Local $aWinList = WinList()
For $i = 1 To $aWinList[0][0]
    If $aWinList[$i][0] <> "" And BitAND(WinGetState($aWinList[$i][1]), 2) Then
        _ArrayAdd($aPrograms, $aWinList[$i][0] & "|" & $aWinList[$i][1])
    EndIf
Next
_ArrayDisplay($aPrograms)
MsgBox(0, "", UBound($aPrograms))

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...