deef99 Posted December 7, 2010 Share Posted December 7, 2010 (edited) I have a text file with 800 lines. I need to search for a particular Heat Number [which in the array will be Column 18]. I can get somewhat of a 2d display of the array, but I can't figure out how to break up the text file first so that each field is in a column. Here is what I have so far: this text file is called: Heatlist.txt M;P;Eddie;Jones;;;34;F;A;Ann;Year;;;4294967295;Academy Ballroom;5;12/04/2010 23:38;Heat 306;Superstars;CC/R/SW/B/M;Open;C;1; M;P;Phillip;Darley;;;42;F;A;Jane;Richards;;;4294967295;Darley's Ballroom;5;12/04/2010 23:38;Heat 306;Superstars;CC/R/SW/B/M;Open;C;4; M;P;Phillip;Darley;;;42;F;P;Mary;Strayer;;;4294967295;Darley's Ballroom;5;12/05/2010 00:10;Pro heat 2;Professional Showdance;;;;1; #include "array.au3" #include "File.au3" #include "Date.au3" #include "String.au3" _FileReadToArray("C:\cmp\heatlist.txt",$aResult) _ArrayDisplay($aResult,"Test") For $iIndex = 1 To $aResult[0] If StringInStr($aResult[$iIndex], "Heat 306") Then MsgBox(4096,"Yes!","r") EndIf Next I can get all the records to display, but all the data is in Column 0. Where am I going wrong? Edited December 7, 2010 by deef99 Link to comment Share on other sites More sharing options...
MrMitchell Posted December 7, 2010 Share Posted December 7, 2010 Might have something to do with how each line is broken in the original heatlist.txt file. I copied and pasted the text you provided into notepad then ran the script and it worked fine for me... Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 7, 2010 Share Posted December 7, 2010 The _FileReadToArray() reads each entire line into a single element of a 1D array. Look for the various examples posted to read CSV files into a 2D array, some have user-specified delimiter so you can set ";" vice ",". 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...
deef99 Posted December 7, 2010 Author Share Posted December 7, 2010 Might have something to do with how each line is broken in the original heatlist.txt file. I copied and pasted the text you provided into notepad then ran the script and it worked fine for me... But...how can it put each piece of data for each record when we have not told it what the seperator [the ;] is? I get an array of all the records, but each record of data is all in Column 0, not seperated into columns by the ; delimiter. Link to comment Share on other sites More sharing options...
deef99 Posted December 7, 2010 Author Share Posted December 7, 2010 The _FileReadToArray() reads each entire line into a single element of a 1D array. Look for the various examples posted to read CSV files into a 2D array, some have user-specified delimiter so you can set ";" vice ",". I agree...but I have not been able to find one yet via my search of this forum... Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 7, 2010 Share Posted December 7, 2010 Here's just to get you started. 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...
BrewManNH Posted December 8, 2010 Share Posted December 8, 2010 (edited) You could use something like this: $File = FileOpen("C:\cmp\heatlist.txt", 0) While 1 $ReadLine = FileReadLine($File) ; Reads in one line of the file at a time If @error then ExitLoop ; if it got to the end of the file exit the while loop $Array = StringSplit($ReadLine, ";") ; splits the read line using the ";" as the place to split each element ;<do what you need to do with the array contents here> Wend Edited December 8, 2010 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator 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