Jump to content

Muti-Dimensional Array, Please Assist!


Recommended Posts

I'm looking to figure out how to make a multi-dimensional Array,

like one that holds a person's first and last name & a date

ex.. Array[1][1] = $name $Date

but I don't know how to get it to work, everything I try gives an error.

Can someone please show me the correct syntax to make a new entry into a database, that will hold the name and date.

I tried this: _ArrayAdd( $DataBase, $Name - $Date)

but it gives an error so must not be right.

also I did Global $DataBase[1][1]

is that right?

Edited by RiCK_420_333
Link to comment
Share on other sites

are you saying you want it to assign $database[name][date]?

like these?

$name = "name"
$date = "date"
Global $array[2][2]
$array[1][0] = $name
$array[1][1] = $date
Msgbox(0,"Test",$array[1][0] & "-" & $array[1][1])

$array[1][1] = $name & "-" & $date
MsgBox(0,"Test",$array[1][1])

If that means like [1][1] would be like "John Doe" "11/11/06"

and [2][2] would be like "Sally Joe" "12/02/92

or am I confused?

Link to comment
Share on other sites

Your using an array incorrectly if your going to increase each array by one each time ([1][1] then [2][2] ) your better off with a single dimensional array

#include <Array.au3>
Global $Array[2][2]
$Array[1][1] = "Sally Joe - 5/4/2006"
    $path = StringSplit($Array[1][1],"-");; this gives $path[1] = to Sally Joe and $path[2] = to 5/4/2006
_ArrayDisplay($path,'')
Edited by thatsgreat2345
Link to comment
Share on other sites

Your using an array incorrectly if your going to increase each array by one each time ([1][1] then [2][2] ) your better off with a single dimensional array

Your interpreting it as since there is 2 dimensions your able to pass to parameters to it but that is not true

#include <Array.au3>
Global $Array[2][2]
$Array[1][1] = "Sally Joe - 5/4/2006"
    $path = StringSplit($Array[1][1],"-");; this gives $path[1] = to Sally Joe and $path[2] = to 5/4/2006
_ArrayDisplay($path,'')

Well originally I did have a single dimension array, like "John Doe" & " ~ " & "11/11/11"

But i also tried making a search feature for the database

and if you only search for john doe it would not find any results, only if you have the complete string

any suggestion on that? and also it seems _ArrayAdd() only works for single dimensions?

Is there any available #include for multidimensional array support?

ALso I agree with you, I think I am using multidimnesional arrays wrong, I am kind of confused about it.

Link to comment
Share on other sites

if you would like help with your code and better possible suggestions do post it and you are more likely to get help

and for search feature if you do use a single dimensional array check out StringInStr

quick example

Global $array[3][3]

$array[1][1] = "Johnny Boy"
$array[1][2] = "5/23/2006"
$array[2][1] = "Salley Doe"
$array[2][2] = "5/5/2006"
For $i = 1 to 2
    For $j = 1 to 2
        MsgBox(0,"Test",$array[$i][$j])
    Next
Next
Edited by thatsgreat2345
Link to comment
Share on other sites

On the 2d array subject, I understand them better when they're laid out like this:

Dim $array[5][5] = [['name 1', 'name 2', 'name 3', 'name 4', 'name 5'], ['date 1', 'date 2', 'date 3', 'date 4', 'date 5']]

For $i = 0 To 4
    MsgBox(0, 'D1', $array[0][$i])
Next

For $i = 0 To 4
    MsgBox(0, 'D2', $array[1][$i])
Next
Link to comment
Share on other sites

Func Add()
    $NameIs = GUICtrlRead ( $Name )
    If $NameIs = "" Then 
        MsgBox( 1, "ATTENTION!", "You Must Enter A Name To Add before clicking the Add button." )
    Else
        $BirthDateIs = GUICtrlRead ( $BirthDate )
    EndIf
    If $BirthDateIs = "" Then 
        MsgBox( 1, "ATTENTION!", "You Must Enter A Birth Date To Add before clicking the Add button." )
    Else
        $Temp = $NameIs & " ~ " & $BirthDateIs
        _ArrayAdd( $DataBase, $Temp)
        _ArraySort( $DataBase )
        $DataBase[0] = UBound( $DataBase )-1
        _FileWriteFromArray( "DataBase.dat", $DataBase, 1 )
        GUICtrlSetData( $Name, "" )
        GUICtrlSetData( $BirthDate, "" )
    EndIf

EndFunc

Func Remove()
    $RemoveThis = InputBox( "Remove An Entry From The DataBase: ", "Remove Which Entry Number?" )
    If $RemoveThis <> "" Then
        _ArrayDelete( $DataBase , $RemoveThis )
        $DataBase[0][0] = UBound( $DataBase )-1
        _FileWriteFromArray( "DataBase.dat", $DataBase, 1 )
    EndIf
EndFunc

Func ShowList()
    _ArrayDisplay( $DataBase, "Birthdays DataBase:" )
EndFunc

Func Search()
    $NameIs = GUICtrlRead ( $Name )
    $BirthDateIs = GUICtrlRead ( $BirthDate )
    If $NameIs = "" And $BirthDateIs = "" Then 
        MsgBox( 1, "ATTENTION!", "You Must Enter A Name or Date to Search for before clicking the Search button." )
    Else
        $Temp = $NameIs & " ~ " & $BirthDateIs
        $Pos = _ArraySearch( $DataBase, $Nameis - $BirthDateIs )
        Select
            Case $Pos = -1
                MsgBox(0, "Not Found", '"' & $Temp & '" was not found in the array.')
            Case Else
                MsgBox(0, "Found", '"' & $Temp & '" was found in the array at pos ' & $Pos & ".")
        EndSelect
    EndIf
EndFunc

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