Mateo Posted January 5, 2021 Share Posted January 5, 2021 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 More sharing options...
Mateo Posted January 5, 2021 Author Share Posted January 5, 2021 (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 January 5, 2021 by Mateo Link to comment Share on other sites More sharing options...
Sidley Posted January 5, 2021 Share Posted January 5, 2021 (edited) The first one seems to work for me without errors. Edit: Not if I take out the _ArrayDisplay($aPrograms[0]) line though. Edited January 5, 2021 by Sidley Link to comment Share on other sites More sharing options...
Mateo Posted January 5, 2021 Author Share Posted January 5, 2021 1 minute ago, Sidley said: The first one seems to work for me without errors. Does the MsgBox show you anything? Link to comment Share on other sites More sharing options...
Nine Posted January 5, 2021 Share Posted January 5, 2021 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)) Mateo and Sidley 2 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Mateo Posted January 5, 2021 Author Share Posted January 5, 2021 Nine, Wow! thank you very very much! you helped me alot! Link to comment Share on other sites More sharing options...
Musashi Posted January 5, 2021 Share Posted January 5, 2021 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)) TheXman 1 "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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now