Jump to content
Mateo

Error accessing 2D array

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

 

Share this post


Link to post
Share on other sites
Posted (edited)
#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

Share this post


Link to post
Share on other sites
Posted (edited)

The first one seems to work for me without errors.

Edit: Not if I take out the _ArrayDisplay($aPrograms[0]) line though.

Edited by Sidley

Share this post


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

The first one seems to work for me without errors.

Does the MsgBox show you anything?

Share this post


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

 

Share this post


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

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...