Jump to content

_ArrayAdd with two-dimensional arrays?


Recommended Posts

The help file only showed it working on a one-dimensional array, and I keep getting an "Array variable has incorrect number of subscripts or subscript dimension range exceeded." error after using it. My question is, does it work for two-dimensional arrays? Here's a snippet of the code I'm using:

Global $bookmarks[1][2]
$bookmarks[0][0] = GUICtrlCreateMenu("Bookmarks")

Func loadBookmarks($section = "Roots", $index = 0)
    GUICtrlSetData($edit, @CRLF & "Loading bookmarks...", "append")
    $file = @ScriptDir & "\res\bookmarks.ini"
    Local $i
    Local $temp = IniReadSection($file, $section)
    If not IsArray($temp) Then MsgBox(48, "Error!", "Could not load " & $file & @CRLF & "There will be no bookmarks")
    For $i = 1 to $temp[0][0]
        If $temp[$i][1] == "folder" Then
            _ArrayAdd($bookmarks, GUICtrlCreateMenu($temp[$i][0], $bookmarks[$index][0]))
            loadBookmarks($temp[$i][0], $index + 1)
        Else
            MsgBox(0, "", $index)
            _ArrayAdd($bookmarks, GUICtrlCreateMenuItem($temp[$i][0], $bookmarks[$index - 1][0])) ;<-- ERROR IS ON THIS LINE, ($index - 1) = 0
            $bookmarks[$i][1] = $temp[1][1]
            GUICtrlSetTip($bookmarks[$i][0], $bookmarks[$i][1])
        EndIf
    Next
    GUICtrlSetData($edit, @CRLF & "Finished loading bookmarks", "append")
EndFunc

[EDIT]

Hmm, I changed the _ArrayAdd call to this "_ArrayAdd($bookmarks[0][0], GUICtrlCreateMenu($temp[$i][0], $bookmarks[$index][0]))" and there aren't any errors, but I think that's adding a value to the second dimension instead of the first...

[EDIT]

Nope, of course it was a problem on my end again.

Delete anyone?

Edited by magician13134
Link to comment
Share on other sites

  • Developers

The help file only showed it working on a one-dimensional array, and I keep getting an "Array variable has incorrect number of subscripts or subscript dimension range exceeded." error after using it. My question is, does it work for two-dimensional arrays? \

Simple: It doesn't. this UDF only works with single dimension Arrays.

Just code it yourself using redim.

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

I posted 2D-enabled versions called __ArrayAdd() and __ArrayConcatenate(). Note the double underscores to differentiate these from the standard UDF function names. If these are not exactly what you need, they should at least give you somewhere to start from.

:)

Edit: for readability

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Wait... it doesn't work? It seems to be working in my code.

Later in my script I'm going to need to use some fountions like _ArraryDelete on a two dimensional array... Will that not work?

For instance I have a grid and I want to be able to delete cells, rows, and columns, and the grid is represented my a two-dimensional array... How would I do that?

Edited by magician13134
Link to comment
Share on other sites

  • 1 year later...

Try that:

Func _ArrayAdd2(ByRef $avArray, $vValue, $x, $y)
    If $x > UBound($avArray)-1 Then
        ReDim $avArray[$x+1][UBound($avArray, 2)]
    EndIf
    If $y > UBound($avArray, 2)-1 Then
        ReDim $avArray[UBound($avArray)][$y+1]
    EndIf
    $avArray[$x][$y] = $vValue
    Return True
EndFunc
Edited by vampirevn01
Link to comment
Share on other sites

  • 2 years later...

while using the "SQLite.au3" functions i recieve an error that says there is no EndFunc for _ArrayAdd in "Array.au3" but when i checed the include code there is, does anyone knows why i recieve this error?

Or how ti fix it?

thanks in advance

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