dwaynek Posted July 29, 2008 Share Posted July 29, 2008 i'd like to automatically create a 2 column dynamic array that say reads from a list or a file that contains eg: ann, 23 bob, 12 carol, 56 doug, 62 and automatically inserts these values into an array. Link to comment Share on other sites More sharing options...
newbiescripter Posted July 29, 2008 Share Posted July 29, 2008 (edited) Here is an example that shows how you could do: #Include <File.au3> #Include <Array.au3> $servers = FileOpenDialog("Open txt files", @DesktopDir & "", "Text File (*.txt)", 1 ) If @error Then Exit Global $loadArray, $Data Dim $dataArray[1][2] _FileReadToArray($servers, $loadArray) ;_ArrayDisplay($loadArray) ;_ArrayDisplay($dataArray) For $i = 1 to Ubound($loadArray)-1 $Data = StringSplit($loadArray[$i], ", ",1) ReDim $dataArray[$i+1][2] $dataArray[$i][0] = $Data[1] $dataArray[$i][1] = $Data[2] $dataArray[0][0] = $i Next _ArrayDisplay($dataArray) Regards Edited July 29, 2008 by newbiescripter Link to comment Share on other sites More sharing options...
dwaynek Posted July 30, 2008 Author Share Posted July 30, 2008 (edited) i'm getting an error when i run your script. it says: line 17: $dataArray[$i][1]=$Data[2] Array variable has incorrect number of subscripts or subscript dimension range exceeded. Edited July 30, 2008 by dwaynek Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 30, 2008 Share Posted July 30, 2008 i'm getting an error when i run your script. it says: line 17: $dataArray[$i][1]=$Data[2] Array variable has incorrect number of subscripts or subscript dimension range exceeded. The problem is blank or mis-formatted lines will not produce the expected StringSplit() array, so some error checking is required. Try changing this section: Dim $dataArray[1][2] = [[0, ""]] _FileReadToArray($servers, $loadArray) For $i = 1 To UBound($loadArray) - 1 If StringStripWS($loadArray[$i], 8) <> "" Then $Data = StringSplit($loadArray[$i], ", ", 1) If UBound($Data) = 3 Then ReDim $dataArray[UBound($dataArray) + 1][2] $dataArray[0] += 1 $dataArray[$dataArray[0]][0] = $Data[1] $dataArray[$dataArray[0]][1] = $Data[2] EndIf EndIf Next 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 More sharing options...
Kovitt Posted July 30, 2008 Share Posted July 30, 2008 Array that adapts to the number of items in your file.. $NumLines = _FileCountLines("TextFile.txt") Dim $Array[$NumLines] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now