Jump to content

Multi-Dim Array Matrix


Recommended Posts

I'm trying to take a square amount of text (4x4), for example:

abcdefghijklmnop

and assign it to an array so that it could be visually represented as

abcd

efgh

ijkl

mnop

then I should be able to say

Msgbox(0, "", $array[3][2] )

and have it return "j" because that's the value in the 3rd row, 2nd column.

I'm still learning multidimensioanl arrays, so if this is possible, i'd really appreciate the help.

Thanks

Link to comment
Share on other sites

It looks like you've pretty well got it (syntax looks right, etc), what's the question?

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

$array[3][2] would most likely return O since Array dimensions in AutoIt are zero-based. To access the second col in the third row, you have to use $array[2][1] :idea:

Here is a PDF i made some time ago: MultiDimArrays.pdf

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

To declare it that way:

Global $aArray[4][4] = [["a", "b", "c", "d"], ["e", "f", "g", "h"], ["i", "j", "k", "l"], ["m", "n", "o", "p"]]
ConsoleWrite("[3][2] = " & $aArray[3][2] & @LF)

To take a string of unknown length and split it in columns of 4:

Global $aArray[1][1], $sString = "abcdefghijklmnopqrs"

$iRows = Ceiling(StringLen($sString) / 4)
ReDim $aArray[$iRows][4]
For $r = 0 To $iRows - 1
    For $c = 0 To 3
        $aArray[$r][$c] = StringMid($sString, ($r * 4) + 1 + $c, 1)
    Next
Next

ConsoleWrite("[3][2] = " & $aArray[3][2] & @LF)

Notice that either way $aArray[3][2] is "o", because array indexes are 0-based. So that's the fourth row, third column.

:idea:

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

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