Sign in to follow this  
Followers 0
noleghair

multi dimentional file read to array

10 posts in this topic

What i have here is a script that reads the values of a 2 files and then and loads them into 2 arrays so i can use those arrays to populate 2 lists. After that i manipulate the lists and have all my fun. What im wondering is how i can read a single file into 2 different arrays (or a multidimentional array) that would allow me to do the same thing without having to have 2 files. The only constraint is that the parts have to be on the same line, so i cannot use section breaks and so on. also, i would like it to be impervious to missing parts of the line EG "line1a,line1b" would work, but so would "line1a," and ",line1b". If there is nothing there, it would just return an empty value

Thank you

#include <file.au3>

#include <GUIConstants.au3>

GUICreate("GUI",500,350,200,200)

GUISetState (@SW_SHOW)

Opt("GUIOnEventMode",1)

Dim $aD

If Not _FileReadToArray("file1.txt",$aD) Then

MsgBox(4096,"Error", " Error reading log to Array error:" & @error)

Exit

EndIf

Dim $aP

If Not _FileReadToArray("file2.txt",$aP) Then

MsgBox(4096,"Error", " Error reading log to Array error:" & @error)

Exit

EndIf

$PList=""

For $x=1 to $aP[0]

$Plist = $PList & "|" & $aP[$x]

Next

$DList=""

For $x=1 to $aD[0]

$Dlist = $DList & "|" & $aD[$x]

Next

.

.

.

.

.

$n1=GuiCtrlCreateList("", 10, 10, 235, 300,"LBS_NOTIFY | WS_VSCROLL | WS_BORDER")

GUICtrlSetFont($n1,20,300)

GuiCtrlSetData($n1, $PList, $aP[1])

$n2=GuiCtrlCreateList("", 255, 10, 235, 300,"LBS_NOTIFY | WS_VSCROLL | WS_BORDER")

GUICtrlSetFont($n2,20,300)

GuiCtrlSetData($n2, $DList, $aD[1])

.

.

.

.

.

and so on

Share this post


Link to post
Share on other sites



Wow that's totally confusing... You want 1 file to do what 2 files are doing? Do both files contain the exact information or something?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

no, sorry, i will try to explain better. Think of it in database terms. I want one file to hold all of my records, but each record has multiple fields, all delimeted by a comma ",". I want to read each field of each record into a multi dimentional array. so if i wanted to pull the information from the 1st field in the 4th record i could do that. with a call like (in no way is this correct) $value[4][1].

The specific use is i want to show only the first field of each record in a list, but when that 1 item is activated, the script will open the program in field 2 with the command in field 3

hope that makes better sense (and i hope its possible with a text document)

Share this post


Link to post
Share on other sites

Trying to grasp... Something like this?

$String1 = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o'
$String2 = 'P,Q,R,S,T,U,V,W,X,Y,Z'
$Sp1 = StringSplit($String1, ',', 1)
$Sp2 = StringSplit($String2, ',', 1)

Dim $My2Dim[UBound($Sp1)][UBound($Sp2)]
For $i = 1 To UBound($Sp1) - 1
    $My2Dim[$i][0] = $Sp1[$i]
Next
For $x = 1 To UBound($Sp2) - 1
    $My2Dim[0][$x] = $Sp2[$x]
Next

For $icount = 1 To UBound($Sp1) - 1
    MsgBox(64, 'Info:', $My2Dim[$icount][0])
Next

For $xcount = 1 To UBound($Sp2) - 1
    MsgBox(64, 'Info2:', $My2Dim[0][$xcount])
Next
Although this is no different than just using $Sp1 or $Sp2 by themselves IMHO.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

still not what im after. I apologize if i am being unclear.

lets pretend:

i have a text file named "file1" that has the following contents:

solitaire,"solitaire.exe"

hearts,"hearts.exe"

spades,"spades.exe"

; ~ and 100 more entries like that

in this case, 3 lines and thats it, but it needs to be read from the file nonetheless.

then i would have the following code (of sorts)

Dim $aD

If Not _FileReadToArray("file1.txt",$aD) Then

MsgBox(4096,"Error", " Error reading log to Array error:" & @error)

Exit

EndIf

;~ formats file contents to create a list

$DList=""

For $x=1 to $aD[0]

$Dlist = $DList & "|" & $aD[$x]

Next

; ~ makes list and highlights the first entry

$n2=GuiCtrlCreateList("", 255, 10, 235, 300,"LBS_NOTIFY | WS_VSCROLL | WS_BORDER")

GUICtrlSetFont($n2,20,300)

GuiCtrlSetData($n2, $DList, $aD[1])

$n3 = GuiCtrlCreateButton("RUN!!", 200, 305, 100, 30)

GUICtrlSetOnEvent($n3,"fncRUN")

func run()

run( - array variable here- )

endfunc

what i would want the program to do is display only the value of the first field in the record, but when you click run, it runs the program that is associated with that record. The records need to be in a text file and cannot be hard coded in any way.

i dont know if that just complicated things even more, but i hope between the 3 posts it will make sense.

Share this post


Link to post
Share on other sites

this is exactly what you want to do..

#include <GUIConstants.au3>
Global $hide_state = 0, $btn_state = 0, $pass = 0, $slide
Global $Button_[8], $Label_[8], $config_[12]

If Not FileExists(@ScriptDir & "\toolbar.ini") Then Create_ini()
$config_name = IniReadSection(@ScriptDir & "\toolbar.ini", "Config")
If Not IsArray($config_name) Then; this is for older versions retro use
    IniWrite(@ScriptDir & "\toolbar.ini", "Config", 1, "255")
    IniWrite(@ScriptDir & "\toolbar.ini", "Config", 2,  "0"); 0 = left / 1 = right
    $config_name = IniReadSection(@ScriptDir & "\toolbar.ini", "Config")
EndIf
$Label_name = IniReadSection(@ScriptDir & "\toolbar.ini", "Label")
$Launch_name = IniReadSection(@ScriptDir & "\toolbar.ini", "Launch")
If $config_name[2][1] = 0 Then
    $slide = "left"
Else
    $slide = "right"
EndIf

$hwnd= GUICreate("Sliding Launcher", 603, 85, -588, -1, -1,  BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW, $WS_EX_ACCEPTFILES)) 
$config_[1] = GUICtrlCreateLabel("Label Name", 15, 22, 60, 20)
$config_[2] = GUICtrlCreateInput("", 75, 22, 80, 20)
$config_[3] = GUICtrlCreateLabel("Program to Launch", 175, 22, 100, 20)
$config_[4] = GUICtrlCreateInput("", 270, 20, 255, 20)
GUICtrlSetState( -1, $GUI_DROPACCEPTED )
$config_[5] = GUICtrlCreateButton("Cancel", 530, 5, 50, 20)
$config_[6] = GUICtrlCreateButton("Browse", 530, 30, 50, 20)
$config_[7] = GUICtrlCreateButton("Accept", 530, 55, 50, 20)
$config_[8] = GUICtrlCreateSlider(270, 50, 255, 20)
GUICtrlSetLimit($config_[8], 255, 200)
GUICtrlSetData($config_[8], $config_name[1][1])
$config_[9] = GUICtrlCreateRadio("Left Justify", 18, 50)
If $config_name[2][1] = 0 Then GUICtrlSetState( $config_[9], $GUI_CHECKED)
$config_[10] = GUICtrlCreateRadio("Right Justify", 95, 50)
If $config_name[2][1] = 1 Then GUICtrlSetState( $config_[10], $GUI_CHECKED)
$config_[11] = GUICtrlCreateLabel("Transparency", 195, 53, 80, 20)

GUICtrlSetState( $config_[10], $GUI_DISABLE); not developed yet

For $x = 1 To 11
    GUICtrlSetState($config_[$x], $GUI_HIDE)
Next
$author = GUICtrlCreateLabel(" By...   Simucal  &&  Valuater", 120, 25, 400, 40)
GUICtrlSetFont(-1, 20, 700)
$Show = GUICtrlCreateButton(">", 585, 8, 17, 70, BitOR($BS_CENTER, $BS_FLAT))
GUISetState(@SW_HIDE, $hwnd)
WinSetTrans($hwnd, "",$config_name[1][1])

$hwnd2 = GUICreate("Sliding Launcher", 603, 85, 3, -1, -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
$Button_[1] = GUICtrlCreateButton("", 20, 35, 73, 41, $BS_ICON)
GUICtrlSetImage(-1, $Launch_name[1][1])
$Label_[1] = GUICtrlCreateLabel($Label_name[1][1], 20, 8, 73, 17, $SS_CENTER + $SS_SUNKEN)
$Button_[2] = GUICtrlCreateButton("", 100, 35, 73, 41, $BS_ICON)
GUICtrlSetImage(-1, $Launch_name[2][1])
$Label_[2] = GUICtrlCreateLabel($Label_name[2][1], 100, 8, 73, 17, $SS_CENTER + $SS_SUNKEN)
$Button_[3] = GUICtrlCreateButton("", 180, 35, 73, 41, $BS_ICON)
GUICtrlSetImage(-1, $Launch_name[3][1])
$Label_[3] = GUICtrlCreateLabel($Label_name[3][1], 180, 8, 73, 17, $SS_CENTER + $SS_SUNKEN)
$Button_[4] = GUICtrlCreateButton("", 260, 35, 73, 41, $BS_ICON)
GUICtrlSetImage(-1, $Launch_name[4][1])
$Label_[4] = GUICtrlCreateLabel($Label_name[4][1], 260, 8, 73, 17, $SS_CENTER + $SS_SUNKEN)
$Button_[5] = GUICtrlCreateButton("", 340, 35, 73, 41, $BS_ICON)
GUICtrlSetImage(-1, $Launch_name[5][1])
$Label_[5] = GUICtrlCreateLabel($Label_name[5][1], 340, 8, 73, 17, $SS_CENTER + $SS_SUNKEN)
$Button_[6] = GUICtrlCreateButton("", 420, 35, 73, 41, $BS_ICON)
GUICtrlSetImage(-1, $Launch_name[6][1])
$Label_[6] = GUICtrlCreateLabel($Label_name[6][1], 420, 8, 73, 17, $SS_CENTER + $SS_SUNKEN)
$Button_[7] = GUICtrlCreateButton("", 500, 35, 73, 41, $BS_ICON)
GUICtrlSetImage(-1, $Launch_name[7][1])
$Label_[7] = GUICtrlCreateLabel($Label_name[7][1], 500, 8, 73, 17, $SS_CENTER + $SS_SUNKEN)
$Hide = GUICtrlCreateButton("<", 585, 8, 17, 70, BitOR($BS_CENTER, $BS_FLAT, $BS_MULTILINE))
$Edit = GUICtrlCreateButton("[]", 0, 8, 15, 70, BitOR($BS_CENTER, $BS_FLAT, $BS_MULTILINE))
GUICtrlSetTip(-1, "Config")
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd2, "int", 500, "long", 0x00040001);slide in from left
GUISetState()
Sleep(100)
WinSetTrans($hwnd2, "",$config_name[1][1])

Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)
$config_tray = TrayCreateItem("Configure...")
TrayItemSetOnEvent(-1, "Set_config")
TrayCreateItem("")
$exit_tray = TrayCreateItem("Exit  Sliding Launcher")
TrayItemSetOnEvent(-1, "Set_Exit")
TraySetState()

While 1
    $msg1 = GUIGetMsg()
    If $msg1 = $GUI_EVENT_CLOSE Then Exit
    If $msg1 = $Hide Then
        If $pass = 1 Then
            WinSetTitle($hwnd2, "", "Sliding Launcher")
            $pass = 0
        Else
            Slide_out()
        EndIf
    EndIf
    If $msg1 = $Show Then Slide_in()
    If $msg1 = $Edit Then $pass = 1
    $a_pos = WinGetPos($hwnd2)
    $a_pos2 = WinGetPos($hwnd)
    If $a_pos[0] <> 0 And $hide_state = 0 Then
        WinMove($hwnd2, "", 3, $a_pos[1])
        WinMove($hwnd, "", -588, $a_pos[1])
    EndIf
    If $a_pos2[0] <> - 588 And $hide_state = 1 Then
        WinMove($hwnd, "", -588, $a_pos2[1])
        WinMove($hwnd2, "", 3, $a_pos2[1])
    EndIf
    If $pass = 1 Then WinSetTitle($hwnd2, "", "Config Mode - Please Press the Button to Configure...  Press  ""<""  to Cancel")
    If $hide_state = 0 Then
        $a_mpos = GUIGetCursorInfo($hwnd2)
        If IsArray($a_mpos) = 1 Then
            For $b = 1 To 7
                If $a_mpos[4] = $Button_[$b] Then
                    If $b = 1 Then $left = 15
                    If $b > 1 Then $left = (($b - 1) * 80) + 15
                    GUICtrlSetPos($Button_[$b], $left, 30, 83, 46)
                    GUICtrlSetColor($Label_[$b], 0xff0000)
                    GUICtrlSetCursor($Button_[$b], 0)
                    While $a_mpos[4] = $Button_[$b]
                        $msg = GUIGetMsg()
                        If $msg = $Button_[$b] Then
                            If $pass = 0 Then
                                Function($b)
                                ExitLoop
                            Else
                                Set_ini($b)
                                ExitLoop
                            EndIf
                        EndIf
                        $a_mpos = GUIGetCursorInfo($hwnd2)
                        If IsArray($a_mpos) <> 1 Then ExitLoop
                    WEnd
                    $left = $left + 5
                    GUICtrlSetPos($Button_[$b], $left, 35, 73, 41)
                    GUICtrlSetColor($Label_[$b], 0x000000)
                EndIf
            Next
        EndIf
    EndIf
WEnd

Func Slide_in()
    $hide_state = 0
    GUISetState(@SW_HIDE, $hwnd)
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd2, "int", 500, "long", 0x00040001);slide in from left
    WinActivate($hwnd2)
    WinWaitActive($hwnd2)
EndFunc  ;==>Slide_in

Func Slide_out()
    $hide_state = 1
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd2, "int", 500, "long", 0x00050002);slide out to left
    GUISetState(@SW_SHOW, $hwnd)
    WinActivate($hwnd)
    WinWaitActive($hwnd)
EndFunc  ;==>Slide_out

Func Create_ini()
    IniWrite(@ScriptDir & "\toolbar.ini", "Config", 1, "255")
    IniWrite(@ScriptDir & "\toolbar.ini", "Config", 2,  "0"); 0 = left / 1 = right
    IniWrite(@ScriptDir & "\toolbar.ini", "Launch", 1, @ProgramFilesDir & "\Internet Explorer\iexplore.exe")
    IniWrite(@ScriptDir & "\toolbar.ini", "Launch", 2, @SystemDir & "\osk.exe")
    IniWrite(@ScriptDir & "\toolbar.ini", "Launch", 3, @ProgramFilesDir & "\Windows Media Player\wmplayer.exe")
    IniWrite(@ScriptDir & "\toolbar.ini", "Launch", 4, @SystemDir & "\notepad.exe")
    IniWrite(@ScriptDir & "\toolbar.ini", "Launch", 5, @SystemDir & "\calc.exe")
    IniWrite(@ScriptDir & "\toolbar.ini", "Launch", 6, @SystemDir & "\mstsc.exe")
    IniWrite(@ScriptDir & "\toolbar.ini", "Launch", 7, @SystemDir & "\cleanmgr.exe")
    IniWrite(@ScriptDir & "\toolbar.ini", "Label", 1, "IE Explorer")
    IniWrite(@ScriptDir & "\toolbar.ini", "Label", 2, "Keyboard")
    IniWrite(@ScriptDir & "\toolbar.ini", "Label", 3, "Media Player")
    IniWrite(@ScriptDir & "\toolbar.ini", "Label", 4, "Notepad")
    IniWrite(@ScriptDir & "\toolbar.ini", "Label", 5, "Calculator")
    IniWrite(@ScriptDir & "\toolbar.ini", "Label", 6, "Net Service")
    IniWrite(@ScriptDir & "\toolbar.ini", "Label", 7, "Clean Mngr")
EndFunc  ;==>Create_ini

Func Set_ini(ByRef $b)
    Slide_out()
    GUICtrlSetState($author, $GUI_HIDE)
    GUICtrlSetState($Show, $GUI_HIDE)
    For $x = 1 To 11
        GUICtrlSetState($config_[$x], $GUI_SHOW)
    Next
    Sleep(50)
    WinSetTrans($hwnd, "", 0)
    WinMove($hwnd, "", 3, $a_pos[1])
    GUICtrlSetData($config_[2], $Label_name[$b][1])
    GUICtrlSetData($config_[4], $Launch_name[$b][1])
    GUICtrlSetState($config_[4], $GUI_DROPACCEPTED )
    For $x = 1 To $config_name[1][1] Step 3
        WinSetTrans($hwnd, "", $x)
        Sleep(1)
    Next
    GUICtrlSetData($config_[8], $config_name[1][1])
    While 3
        $a_pos = WinGetPos($hwnd)
        WinMove($hwnd, "", 3, $a_pos[1])
        WinMove($hwnd2, "", 3, $a_pos[1])
        $msg3 = GUIGetMsg()
        If $msg3 = $config_[8] Then
            WinSetTrans($hwnd, "", GUICtrlRead($config_[8]))
            WinSetTrans($hwnd2, "", GUICtrlRead($config_[8]))
        EndIf
        If $msg3 = $GUI_EVENT_CLOSE Then Exit
        If $msg3 = $config_[5] Then ExitLoop
        If $msg3 = $config_[6] Then
            $Find = FileOpenDialog("Please Select a Program to Launch", @ProgramFilesDir, "exe (*.exe)", 1 + 2)
            If Not @error = 1 Then GUICtrlSetData($config_[4], $Find)
        EndIf
        If $msg3 = $config_[7] Then
            $temp_info = GUICtrlRead($config_[4])
            If FileExists($temp_info) Then
                If StringInStr($temp_info, ".lnk") Then
                    $details = FileGetShortcut($temp_info)
                    $temp_info = $details[0]
                EndIf
                If StringInStr($temp_info, ".exe") Then
                    IniWrite(@ScriptDir & "\toolbar.ini", "Config", 1, GUICtrlRead($config_[8]))
                    If BitAnd(GUICtrlRead($config_[9]),$GUI_CHECKED) = $GUI_CHECKED then
                        IniWrite(@ScriptDir & "\toolbar.ini", "Config", 2, "0"); 0 = left / 1 = right
                        $slide = "left"
                    Else
                        IniWrite(@ScriptDir & "\toolbar.ini", "Config", 2, "1"); 0 = left / 1 = right
                        $slide = "right"
                    EndIf
                    IniWrite(@ScriptDir & "\toolbar.ini", "Launch", $b, $temp_info)
                    IniWrite(@ScriptDir & "\toolbar.ini", "Label", $b, (GUICtrlRead($config_[2])))
                    $config_name = IniReadSection(@ScriptDir & "\toolbar.ini", "Config")
                    $Label_name = IniReadSection(@ScriptDir & "\toolbar.ini", "Label")
                    $Launch_name = IniReadSection(@ScriptDir & "\toolbar.ini", "Launch")
                    For $x = 1 To 7
                        GUICtrlSetData($Label_[$x], $Label_name[$x][1])
                        GUICtrlSetImage($Button_[$x], $Launch_name[$x][1])
                    Next
                    ExitLoop
                Else
                    MsgBox(262208, "Sorry!", "The ""exe"" file could not be verified   ", 4)
                EndIf
            Else
                MsgBox(262208, "Sorry!", "The file location could not be verified   ", 4)
            EndIf
        EndIf
    WEnd
    For $x = 1 To 11
        GUICtrlSetState($config_[$x], $GUI_HIDE)
    Next
    GUICtrlSetState($author, $GUI_SHOW)
    Sleep(300)
    For $x = $config_name[1][1] To 1 Step - 3
        WinSetTrans($hwnd, "", $x)
        Sleep(1)
    Next
    
    WinMove($hwnd, "", -588, $a_pos[1])
    GUICtrlSetState($Show, $GUI_SHOW)
    WinSetTrans($hwnd, "", $config_name[1][1])
    WinSetTrans($hwnd2, "", $config_name[1][1])
    Slide_in()
EndFunc  ;==>Set_ini

Func Function(ByRef $b)
    Slide_out()
    If FileExists($Launch_name[$b][1]) Then
        $LFile = FileGetShortName($Launch_name[$b][1])
        Run($LFile)
    Else
        MsgBox(262208, "Sorry!", "The file location could not be verified   ", 4)
    EndIf
EndFunc  ;==>Function

Func Set_Exit()
    Exit
EndFunc  ;==>Set_Exit

Func Set_Config()
    $a_pos = WinGetPos($hwnd)
    If $a_pos[0] = 3 Then Return
    Slide_in()
    $pass = 1
EndFunc  ;==>Set_Exit

just 7 at a time, however you can run as many of these as you want

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

still not what im after. I apologize if i am being unclear.

lets pretend:

i have a text file named "file1" that has the following contents:

solitaire,"solitaire.exe"

hearts,"hearts.exe"

spades,"spades.exe"

; ~ and 100 more entries like that

in this case, 3 lines and thats it, but it needs to be read from the file nonetheless.

then i would have the following code (of sorts)

Dim $aD

If Not _FileReadToArray("file1.txt",$aD) Then

MsgBox(4096,"Error", " Error reading log to Array error:" & @error)

Exit

EndIf

;~ formats file contents to create a list

$DList=""

For $x=1 to $aD[0]

$Dlist = $DList & "|" & $aD[$x]

Next

; ~ makes list and highlights the first entry

$n2=GuiCtrlCreateList("", 255, 10, 235, 300,"LBS_NOTIFY | WS_VSCROLL | WS_BORDER")

GUICtrlSetFont($n2,20,300)

GuiCtrlSetData($n2, $DList, $aD[1])

$n3 = GuiCtrlCreateButton("RUN!!", 200, 305, 100, 30)

GUICtrlSetOnEvent($n3,"fncRUN")

func run()

run( - array variable here- )

endfunc

what i would want the program to do is display only the value of the first field in the record, but when you click run, it runs the program that is associated with that record. The records need to be in a text file and cannot be hard coded in any way.

i dont know if that just complicated things even more, but i hope between the 3 posts it will make sense.

Well if that's how your doing it, personally I would make an Ini file to do it:
$FileNameLocation = @DesktopDir & '\IniCheck.ini'
$IniReadArray = IniReadSection($FileNameLocation, 'Section')

For $i = 1 To $IniReadArray[0][0]
    If MsgBox(4, 'Execute', "Do you want to run this program?" & @CR & $IniReadArray[$i][0] & @CR & Execute($IniReadArray[$i][1])) = 6 Then
        Run(Execute($IniReadArray[$i][1]))
    EndIf
Next

[section]

solitaire=@SystemDir & '\sol.exe'

hearts=@SystemDir & '\mshearts.exe'

spades=@ProgramFilesDir & '\MSN Gaming Zone\Windows\shvlzm.exe'

So you could Display: $IniReadArray[$i][0] and if they click on that, then you can Run $IniReadArray[$i][1], Am I understanding that now?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

What i am getting out of this is what i was trying to do is either not possible, or at the least not standard practice. Im thinking i will just use an ini file and get it over with. Thanks for the help. i will admit defeat for now. For future reference though, if anyone knoew how to read a text file that had

1,1a,1b,1c,1d,1e,1f

2,2a,2b,2c,2d,2e,2f

3,3a,3b,3c,3d,3e,3f

4,4a,4b,4c,4d,4e,4f

5,5a,5b,5c,5d,5e,5f

and tell me how to read that into an array so i could call out 4d with something like "$VAR[4][5] that would be awesome

Thanks

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

What i am getting out of this is what i was trying to do is either not possible, or at the least not standard practice. Im thinking i will just use an ini file and get it over with. Thanks for the help. i will admit defeat for now. For future reference though, if anyone knoew how to read a text file that had

1,1a,1b,1c,1d,1e,1f

2,2a,2b,2c,2d,2e,2f

3,3a,3b,3c,3d,3e,3f

4,4a,4b,4c,4d,4e,4f

5,5a,5b,5c,5d,5e,5f

and tell me how to read that into an array so i could call out 4d with something like "$VAR[4][5] that would be awesome

Thanks

Something like this?:
#include <file.au3>
$FilePath = @DesktopDir & '\MultiArrayExample.txt'
$GetArray = _MakeMultiDimArray($FilePath)
If IsArray($GetArray) Then
    For $i = 1 To 5
        For $x = 1 To 6
            MsgBox(0, 'Example', $i & @CR & $GetArray[$i][$x])
        Next
    Next
EndIf

Func _MakeMultiDimArray($hFile, $vDelimeter = ',')
    Local $nArray = '', $iCountNonEmptyLines = 0, $iSecondElement = 0
    If Not _FileReadToArray($hFile, $nArray) Then Return 0
    
    For $iCountLines = 1 To UBound($nArray) - 1
        If $nArray[$iCountLines] <> '' Then
            $iSecondElement = UBound(StringSplit($nArray[$iCountLines], $vDelimeter, 1) - 1)
            ExitLoop
        EndIf
    Next    
    
    For $iCountLines = 1 To UBound($nArray) - 1
        If $nArray[$iCountLines] <> '' Then $iCountNonEmptyLines += 1
    Next
    
    Local $avArray[$iCountNonEmptyLines + 1][$iSecondElement]
    
    For $iCount = 1 To UBound($nArray) - 1
        If $nArray[$iCount] <> '' Then
            $aSplit = StringSplit($nArray[$iCount], $vDelimeter, 1)
            If UBound($aSplit) - 1 > 0 Then
                For $xCount = 2 To UBound($aSplit) - 1
                    $avArray[$aSplit[1]][$xCount - 1] = $aSplit[$xCount]
                Next
            EndIf
        EndIf
    Next
    Return $avArray
EndFunc
I don't know how accurate this is, or if it's even efficient, but it returns a 2 dim array, I used the example

1,1a,1b,1c,1d,1e,1f

2,2a,2b,2c,2d,2e,2f

3,3a,3b,3c,3d,3e,3f

4,4a,4b,4c,4d,4e,4f

5,5a,5b,5c,5d,5e,5f

that you provided in a file to test it, and it looked like it did what you were asking after I tested it.

Edit:

Changed the function an hair.

This is also under the assumption that the 2nd element is always the same Ubound(value)... because all of yours had the same amount of 2nd elements.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I don't know if this would apply to what you're wanting to do, but I had this sitting around from another project, basically, you can pack any variable (save Objects and DllStructs) to a string, and then unpack that string back into a variable. It handles arrays of up to four dimensions and arrays nested in the elements of other arrays. So, you could do something like:

Dim $test[2][2]
$test[0][0] = "test1"
$test[0][1] = "test2"
$test[1][0] = "test3"
$test[1][1] = "test4"
$str = _PackVarToStr($test)
MsgBox(0,"",$str)
oÝ÷ Ù©ÝÚÞ¶êç±Ê{Mú÷]½ßMúÓ~½×owÓ~´ß¯uÛÝôß­7ëÝt÷}7ê׬·]7ëÝt÷}7ê׬·m7ëÝt÷}7ê׬·}7ëÝt÷}7ê׬·Ü¡×'!Êj{az{¬y«­¢+Ø(ÀÌØíÉÉäô}U¹Á­MÑÉQ½YÈ ÀÌØíÍÑȤoÝ÷ ÚÚ¢{Þ®Ûazçl¶¸§¶Úéí¢ç!yÛÚ®&觶¬q«jv«­¬ºÚ"µÍÏOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOBÂÈ[Ý[Û[YNÔXÚÕÔÝ
BÈØÜ[ÛXÚÜÈHXXH[ÈHÝ[ÈÜHÜÙ[[ÈÈ[ÝÂBBBBBØÜXZ[Z[È^H[YÜ]HÈ
[Y[Ú[ÛËÂBBBBBP[ÛÈÝÜÈÝY^È[ÚYH^H[[Y[ËÈ[Y]ÊN    ÌÍÝXÚÕHXXHÈHXÚÙY[ÈHÝ[ËÂBBBBBSÕNXXÈÙHØXÝÜÝXÝÈHÝY]ÂBBBBBÝÜYÈ][YJÊN]ÈXÚÙYÝ[ÈÈH[XÚÙYHÕ[XÚÔÝÕ
BÈ]]ÜÊN[YÚÙ[ÂÏOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOB[ÈÔXÚÕÔÝTY    ÌÍÝXÚÕBSØØ[  ÌÍÚS[Q[ÈHPÝ[
    ÌÍÝXÚÕ
HÈ[XÙ[Y[Ú[ÛÈÙ ÌÍÝXÚÕSØØ[   ÌÍÜÕÝH ][ÝÉÌÍÖÉ][ÝÈ    [È ÌÍÚS[Q[È    [È ][Ý×IÌÍÉ][ÝÈÈ]Ý[ÈÙXÚÙYXXBSØØ[    ÌÍÚPÛÝ[HH  ][ÝÉ][ÝÈÈÝYÛÝ[SØØ[    ÌÍÚPÛÝ[H   ][ÝÉ][ÝÈÈÝYÛÝ[SØØ[    ÌÍÚPÛÝ[ÈH ][ÝÉ][ÝÈÈÝYÛÝ[SØØ[    ÌÍÚPÛÝ[H   ][ÝÉ][ÝÈÈÝYÛÝ[QÜ   ÌÍÚHHHÈ ÌÍÚS[Q[ÂBIÌÍÜÕÝ    [ÏH    ][ÝÉÌÍÖÉ][ÝÈ    [ÈPÝ[
    ÌÍÝXÚÕ ÌÍÚJH    [È ][Ý×IÌÍÉ][ÝÂS^TÙ[XÝBPØÙH ÌÍÚS[Q[ÈOHBBRY  ÌÍÝXÚÕOH   ][ÝÉ][ÝÈ[BBBIÌÍÜÕÝ [ÏH    ][ÝÉÛ[   ÝÉ][ÝÂBBQ[ÙBBBBIÌÍÜÕÝ [ÏH    ÌÍÝXÚÕBBQ[YBPØÙH ÌÍÚS[Q[ÈOHBBBQÜ    ÌÍÚPÛÝ[HHÈPÝ[
    ÌÍÝXÚÕJHHBBBBRY    ÌÍÝXÚÕÉÌÍÚPÛÝ[WHOH   ][ÝÉ][ÝÈ[PÝ[
    ÌÍÝXÚÕÉÌÍÚPÛÝ[WK
HOH[BBBBIÌÍÜÕÝ [ÏH    ][ÝÉÌÍÖÌIÌÍÉÛ[    ÝÉ][ÝÂBBBQ[ÙBBBBBIÌÍÜÕÝ   [ÏHÔXÚÕÔÝ ÌÍÝXÚÕÉÌÍÚPÛÝ[WJBBBBQ[YBBS^BPØÙH   ÌÍÚS[Q[ÈOHBBQÜ ÌÍÚPÛÝ[HHÈPÝ[
    ÌÍÝXÚÕJHHBBBBQÜ   ÌÍÚPÛÝ[HÈPÝ[
    ÌÍÝXÚÕHHBBBBBRY    ÌÍÝXÚÕÉÌÍÚPÛÝ[WVÉÌÍÚPÛÝ[HOH    ][ÝÉ][ÝÈ[ÂBBBBHPÝ[
    ÌÍÝXÚÕÉÌÍÚPÛÝ[WVÉÌÍÚPÛÝ[K
HOH[BBBBBIÌÍÜÕÝ    [ÏH    ][ÝÉÌÍÖÌIÌÍÉÛ[    ÝÉ][ÝÂBBBBQ[ÙBBBBBBIÌÍÜÕÝ [ÏHÔXÚÕÔÝ ÌÍÝXÚÕÉÌÍÚPÛÝ[WVÉÌÍÚPÛÝ[JBBBBBQ[YBBBS^BBS^BPØÙH  ÌÍÚS[Q[ÈOHÂBBQÜ   ÌÍÚPÛÝ[HHÈPÝ[
    ÌÍÝXÚÕJHHBBBBQÜ   ÌÍÚPÛÝ[HÈPÝ[
    ÌÍÝXÚÕHHBBBBBQÜ   ÌÍÚPÛÝ[ÈHÈPÝ[
    ÌÍÝXÚÕÊHHBBBBBBRY ÌÍÝXÚÕÉÌÍÚPÛÝ[WVÉÌÍÚPÛÝ[VÉÌÍÚPÛÝ[×HOH   ][ÝÉ][ÝÈ[ÂBBBBBHPÝ[
    ÌÍÝXÚÕÉÌÍÚPÛÝ[WVÉÌÍÚPÛÝ[VÉÌÍÚPÛÝ[×K
HOH[BBBBBBIÌÍÜÕÝ   [ÏH    ][ÝÉÌÍÖÌIÌÍÉÛ[    ÝÉ][ÝÂBBBBBQ[ÙBBBBBBBIÌÍÜÕÝ   [ÏHÔXÚÕÔÝ ÌÍÝXÚÕÉÌÍÚPÛÝ[WVÉÌÍÚPÛÝ[VÉÌÍÚPÛÝ[×JBBBBBBQ[YBBBBS^BBBS^BBS^BPØÙH  ÌÍÚS[Q[ÈOH
BBQÜ   ÌÍÚPÛÝ[HHÈPÝ[
    ÌÍÝXÚÕJHHBBBBQÜ   ÌÍÚPÛÝ[HÈPÝ[
    ÌÍÝXÚÕHHBBBBBQÜ   ÌÍÚPÛÝ[ÈHÈPÝ[
    ÌÍÝXÚÕÊHHBBBBBBQÜ    ÌÍÚPÛÝ[HÈPÝ[
    ÌÍÝXÚÕ
HHBBBBBBBRY ÌÍÝXÚÕÉÌÍÚPÛÝ[WVÉÌÍÚPÛÝ[VÉÌÍÚPÛÝ[×VÉÌÍÚPÛÝ[HOH    ][ÝÉ][ÝÈ[ÂBBBBBBHPÝ[
    ÌÍÝXÚÕÉÌÍÚPÛÝ[WVÉÌÍÚPÛÝ[VÉÌÍÚPÛÝ[×VÉÌÍÚPÛÝ[K
HOH[BBBBBBBIÌÍÜÕÝ  [ÏH    ][ÝÉÌÍÖÌIÌÍÉÛ[    ÝÉ][ÝÂBBBBBBQ[ÙBBBBBBBBIÌÍÜÕÝ [ÏHÔXÚÕÔÝ ÌÍÝXÚÕÉÌÍÚPÛÝ[WVÉÌÍÚPÛÝ[VÉÌÍÚPÛÝ[×VÉÌÍÚPÛÝ[JBBBBBBBQ[YBBBBBS^BBBBS^BBBS^BBS^Q[Ù[XÝT]    ÌÍÜÕÝ[[ÈÏOIÝ×ÔXÚÕÔÝÏOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOBÂÈ[Ý[Û[YNÕ[XÚÔÝÕ
BÈØÜ[ÛÈHXÚÙYXXHÝ[ÈXÚÈ[ÈHXXKÈ[Y]ÊN ÌÍÜÕÝHHXÚÙYXXHÝ[ÈÈ]YHÔXÚÕÔÝ
BÈ][YJÊNXXHÙH]ØÈÜÙYÈÔXÚÕÔÝ
BÈ]]ÜÊN[YÚÙ[ÂÏOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOB[ÈÕ[XÚÔÝÕTY   ÌÍÜÕÝBSØØ[   ÌÍØZS[Q[ÈHÝ[ÔYÑ^
    ÌÍÜÕÝ  ÌÎNÊÎÌLÉÌÍÉÌLÖÊJ    ÌLÙ
JÎÌL×IÌLÉÌÍÊJ   ÌLÈÊIÌÎNËJBSØØ[ ÌÍØZQ[TÚ^ÖÌWHÈÈÛÛZ[HÚ^HÙXXÚ[Y[Ú[ÛÈÜÙYÝYÚ    ÌÍÜÕÝSØØ[    ÌÍØZQ[TÚ^HH ][ÝÉ][ÝÈÈÈÛÛZ[HÚ^HÙÝ[[Y[Ú[Û[Ý[ÈÜÚ][ÛÜÝ[ÂSØØ[ ÌÍØ]]ÌWHÈÈHY[Y[Ú[ÛY[]H  ÌÍÜÕÝÙY[ÝÜY[ÈÈ[^BSØØ[   ÌÍØ][[Y[ÝH  ][ÝÉ][ÝÈÈÈÛÛZ[XXÚ[[Y[ÈHÝ[ÈÈ]ÈÙYÛH   ÌÍÜÕÝRYÐ^J    ÌÍØZS[Q[ÊH[BIÌÍÜÕÝHÝ[Õ[SY
    ÌÍÜÕÝ  ÌÍØZS[Q[ÖÌWJBBRY   ÌÍØZS[Q[ÖÌH    ÝÈ[BBTQ[H ÌÍØZQ[TÚ^ÖÉÌÍØZS[Q[ÖÌWBBBQÜ ÌÍÚPÛÝ[HHÈ    ÌÍØZS[Q[ÖÌHHBBBBIÌÍØZQ[TÚ^HHÝ[ÔYÑ^
    ÌÍÜÕÝ  ÌÎNÊÎÌLÉÌÍÉÌLÖÊJ    ÌLÙ
JÎÌL×IÌLÉÌÍÊJ   ÌLÈÊIÌÎNËJBBBBIÌÍØZQ[TÚ^ÖÉÌÍÚPÛÝ[WHH   ÌÍØZQ[TÚ^VÌBBBBIÌÍÜÕÝHÝ[Õ[SY
    ÌÍÜÕÝ  ÌÍØZQ[TÚ^VÌWJBBBS^BQ[YBTÙ[XÝBBPØÙH ÌÍØZS[Q[ÖÌHOHBBBRYÝ[Ò[Ý ÌÍÜÕÝ  ][ÝÉÌÍÖÉ][ÝÊH[BBBBIÌÍØ][[Y[ÝHÝ[ÔYÑ^
    ÌÍÜÕÝ  ÌÎNÊÊJ  ÌLÈÊJÎÌLÉÌÍÉÌLÖÊIÌÎNËJBBBBBIÌÍÜÕÝHÝ[Õ[SY
    ÌÍÜÕÝ  ÌÍØ][[Y[ÝÌWJBBBBBRY    ÌÍØ][[Y[ÝÌH    ÉÝÈ  ][ÝÉÛ[   ÝÉ][ÝÈ[BBBBBT]  ÌÍØ][[Y[ÝÌBBBBBQ[ÙBBBBBBT]    ][ÝÉ][ÝÂBBBBQ[YBBBQ[ÙBBBBBRY   ÌÍÜÕÝOH    ][ÝÉÛ[   ÝÉ][ÝÈ[BBBBBT]  ][ÝÉ][ÝÂBBBBQ[ÙBBBBBBT]    ÌÍÜÕÝBBBBQ[YBBBQ[YBBPØÙH ÌÍØZS[Q[ÖÌHOHBBBBTQ[H  ÌÍØ]]ÉÌÍØZQ[TÚ^ÖÌWBBBBQÜ ÌÍÚPÛÝ[HHÈ    ÌÍØZQ[TÚ^ÖÌHHBBBBBIÌÍØ]]ÉÌÍÚPÛÝ[WHHÕ[XÚÔÝÕ  ÌÍÜÕÝBBBBS^BBPØÙH    ÌÍØZS[Q[ÖÌHOHBBBTQ[H   ÌÍØ]]ÉÌÍØZQ[TÚ^ÖÌWVÉÌÍØZQ[TÚ^ÖÌWWBBBBQÜ   ÌÍÚPÛÝ[HHÈ    ÌÍØZQ[TÚ^ÖÌHHBBBBBQÜ ÌÍÚPÛÝ[HÈ ÌÍØZQ[TÚ^ÖÌWHHBBBBBBIÌÍØ]]ÉÌÍÚPÛÝ[WVÉÌÍÚPÛÝ[HHÕ[XÚÔÝÕ ÌÍÜÕÝBBBBBS^BBBS^BBPØÙH  ÌÍØZS[Q[ÖÌHOHÂBBBTQ[H ÌÍØ]]ÉÌÍØZQ[TÚ^ÖÌWVÉÌÍØZQ[TÚ^ÖÌWWVÉÌÍØZQ[TÚ^ÖÌWBBBBQÜ  ÌÍÚPÛÝ[HHÈ    ÌÍØZQ[TÚ^ÖÌHHBBBBBQÜ ÌÍÚPÛÝ[HÈ ÌÍØZQ[TÚ^ÖÌWHHBBBBBBQÜ   ÌÍÚPÛÝ[ÈHÈ   ÌÍØZQ[TÚ^ÖÌHHBBBBBBBIÌÍØ]]ÉÌÍÚPÛÝ[WVÉÌÍÚPÛÝ[VÉÌÍÚPÛÝ[×HHÕ[XÚÔÝÕ    ÌÍÜÕÝBBBBBBS^BBBBS^BBBS^BBPØÙH   ÌÍØZS[Q[ÖÌHOH
BBBTQ[H ÌÍØ]]ÉÌÍØZQ[TÚ^ÖÌWVÉÌÍØZQ[TÚ^ÖÌWWVÉÌÍØZQ[TÚ^ÖÌWVÉÌÍØZQ[TÚ^ÖÌ×WBBBBQÜ   ÌÍÚPÛÝ[HHÈ    ÌÍØZQ[TÚ^ÖÌHHBBBBBQÜ ÌÍÚPÛÝ[HÈ ÌÍØZQ[TÚ^ÖÌWHHBBBBBBQÜ   ÌÍÚPÛÝ[ÈHÈ   ÌÍØZQ[TÚ^ÖÌHHBBBBBBBQÜ   ÌÍÚPÛÝ[HÈ ÌÍØZQ[TÚ^ÖÌ×HHBBBBBBBBIÌÍØ]]ÉÌÍÚPÛÝ[WVÉÌÍÚPÛÝ[VÉÌÍÚPÛÝ[×VÉÌÍÚPÛÝ[HHÕ[XÚÔÝÕ  ÌÍÜÕÝBBBBBBBS^BBBBBS^BBBBS^BBBS^BQ[Ù[XÝBT]   ÌÍØ]]Q[Y[[ÈÏOIÝ×Õ[XÚÔÝÕ

Edit: Edited long lines to be forum-friendly.

Edited by neogia

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

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
Sign in to follow this  
Followers 0