erik7426 0 Posted October 7, 2010 I have used FileReadToArray in the past for one dimensional arrays, this time however the file contains multiple data elements. I need to be able to read a text file that contains 3 fields (PC name, IP Address, Port Number) into a multi-dimensional array. The file is currently tab delimited, but that could be changed if needed. Can anyone provide any guidance on the best way to accomplish this? Share this post Link to post Share on other sites
enaiman 16 Posted October 7, 2010 - Declare the big array to hold your results - read text file using _FileReadToArray - split every element from your array using the delimiter of your choice and populate your "big" array elements Easy enough SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example scriptwannabe "Unbeatable" Tic-Tac-ToePaper-Scissor-Rock ... try to beat it anyway :) Share this post Link to post Share on other sites
trung0407 0 Posted October 8, 2010 FileReadLine => to read each line Dim $data[] StringSplit, with tab as delimiter => return an array of data ($line) $data[0] = StringSplit... loop to read the next line Share this post Link to post Share on other sites
Tlem 6 Posted October 8, 2010 you can find a function here : http://www.autoitscript.fr/forum/viewtopic.php?f=21&t=2741 It's on French forum, but the comments of the function are in English. Best Regards.Thierry Share this post Link to post Share on other sites
Mison 1 Posted October 8, 2010 Hi Erik, You can use nested loop. #include <Array.au3> ; for _ArrayDisplay Local $array [3][3] ; Fixed size 2d array. Use ReDim to expand array. $data = FileRead("data.txt") $row = StringSplit($data,@CRLF,3) ; flag 1 + 2. For more information, refer to the help file. For $i = 0 To UBound($row)-1 $col = StringSplit($row[$i],",",2) For $j = 0 To UBound($col)-1 $array[$i][$j] = $col[$j] Next Next _ArrayDisplay($array) data.txt ==> x1,x2,x3 y1,y2,y3 z1,z2,z3 Hi ;) Share this post Link to post Share on other sites
erik7426 0 Posted October 8, 2010 Thanks for all the advice. I ended up piecing code together that I found from several examples. This is what I came up with... #include <file.au3> #include <array.au3> Dim $aRows If Not _FileReadToArray("TTYID.txt", $aRows) Then MsgBox(4096, "Error", " Error reading file to Array error:" & @error) Exit EndIf Global $myTTYID[$aRows[0]][3] For $r = 1 To $aRows[0] $aCols = StringSplit($aRows[$r], @TAB, 1) For $c = 1 To $aCols[0] $myTTYID[$r - 1][$c - 1] = $aCols[$c] Next Next _ArrayDisplay($myTTYID, "$myTTYID") I don't know if it was the best or the most simple way, but it works... Share this post Link to post Share on other sites