deef99 Posted September 15, 2011 Share Posted September 15, 2011 Ok...trying to do what I thought was fairly simple... I have a file - example below of some lines. I need to find 2 strings of data, and write them out to a file. I can find the first one...but having trouble gettin the second. My thought was: find the "Heat List for:" ...then first the very next one. Then go back 2 lines and get the HEAT line. First person done...write to file, move to next person. The goal is to create a file with Dancer's Name and Last Heat Number. FILE EXAMPLE: Heat list for:Vance Allen [The Tango], 27 entriesPractice [saturday September 17, 2011, 10:00AM]American Smooth & International Standard Single Dance Events [saturday September 17, 2011, 11:00AM] With Stu Rozier, number 12 11:19AM Heat 14 L-B Bronze I Closed Waltz 11:21AM Heat 15 L-B Bronze I Closed Tango 11:22AM Heat 16 L-B Bronze I Closed Foxtrot 11:33AM Heat 22 L-B Bronze II Closed Waltz 11:35AM Heat 23 L-B Bronze II Closed Tango 11:36AM Heat 24 L-B Bronze II Closed Foxtrot 11:38AM Heat 25 L-B Bronze II Closed V. Waltz 12:05PM Heat 43 L-B Bronze I Closed V. Waltz-----------------------------------PAGE BREAK-----------------------------------Heat list for:Lenn Also, number 17 [Dance City Ballroom], 4 entriesPractice [saturday September 17, 2011, 10:00AM]American Smooth & International Standard Single Dance Events [saturday September 17, 2011, 11:00AM] With Margie 11:07AM Heat 6 L-D Bronze II Closed Foxtrot 11:53AM Heat 35 L-D Bronze II Closed Waltz 11:54AM Heat 36 L-D Bronze II Closed TangoAmerican Smooth 3 Dance Challenge Events [saturday September 17, 2011, 12:25PM] 01:13PM Heat 65 L-D Pro/Am TangoAmerican Rhythm & International Latin Single Dance Events [saturday September 17, 2011, 02:00PM]Rhythm 3 Dance Challenge Events [saturday September 17, 2011, 04:33PM]-----------------------------------PAGE BREAK-----------------------------------Heat list for:Margie Doe [Dance City Ballroom], 4 entries Here's what I have left of my code that didn't work: #Region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_Outfile=C:\cmpmgr\Top.exe#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****#include <File.au3>$file = FileOpen("c:\cmpmgr\top\lastheat.txt", 0)$result = ""$vnum = ""$d1 = ""$d2 = ""$logfile = "c:\cmpmgr\top\LAST.txt"FileDelete($logfile)While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $result = StringInStr($line, "Heat List for:") If $result > 0 Then $d1 = $line EndIf $result = StringInStr($line, "Heat List for:") MsgBox(0, "vnum:", $result) $result = $result - 2$result = StringInStr($line, "M HEAT") $vnum = $lineMsgBox(0, "vnum:", $vnum) FileWrite($logfile, $d1 & " - " & $vnum & @CRLF)WEndFileClose($logfile) Link to comment Share on other sites More sharing options...
somdcomputerguy Posted September 15, 2011 Share Posted September 15, 2011 Try this function, _FileReadToArray. Putting the file into an array and manipulating that data, while maybe not 'fairly simple', may be easier in the long run.. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 15, 2011 Moderators Share Posted September 15, 2011 deef99, If I use this file: Heat list for:Vance Allen [The Tango], 27 entries Practice [Saturday September 17, 2011, 10:00AM] American Smooth & International Standard Single Dance Events [Saturday September 17, 2011, 11:00AM] With Stu Rozier, number 12 11:19AM Heat 14 L-B Bronze I Closed Waltz 11:21AM Heat 15 L-B Bronze I Closed Tango 11:22AM Heat 16 L-B Bronze I Closed Foxtrot 11:33AM Heat 22 L-B Bronze II Closed Waltz 11:35AM Heat 23 L-B Bronze II Closed Tango 11:36AM Heat 24 L-B Bronze II Closed Foxtrot 11:38AM Heat 25 L-B Bronze II Closed V. Waltz 12:05PM Heat 43 L-B Bronze I Closed V. Waltz -----------------------------------PAGE BREAK----------------------------------- Heat list for:Lenn Also, number 17 [Dance City Ballroom], 4 entries Practice [Saturday September 17, 2011, 10:00AM] American Smooth & International Standard Single Dance Events [Saturday September 17, 2011, 11:00AM] With Margie 11:07AM Heat 6 L-D Bronze II Closed Foxtrot 11:53AM Heat 35 L-D Bronze II Closed Waltz 11:54AM Heat 36 L-D Bronze II Closed Tango American Smooth 3 Dance Challenge Events [Saturday September 17, 2011, 12:25PM] 01:13PM Heat 65 L-D Pro/Am Tango American Rhythm & International Latin Single Dance Events [Saturday September 17, 2011, 02:00PM] Rhythm 3 Dance Challenge Events [Saturday September 17, 2011, 04:33PM] -----------------------------------PAGE BREAK----------------------------------- Heat list for:Margie Doe [Dance City Ballroom], 4 entries Practice [Saturday September 17, 2011, 10:00AM] American Smooth & International Standard Single Dance Events [Saturday September 17, 2011, 11:00AM] With Fred 03:10PM Heat 97 L-D Pro/Am Tango Then this script works: expandcollapse popup#include <File.au3> #include <Array.au3> Global $aLines _FileReadToArray("mylist.txt", $aLines) $iStart = 0 $sSections = "" While 1 $iIndex = _ArraySearch($aLines, "Heat list for:", $iStart, 0, 0, 1) If $iIndex = -1 Then ExitLoop $sSections &= $iIndex & "|" $iStart = $iIndex + 1 WEnd $sSections &= $aLines[0] + 2 $aSections = StringSplit($sSections, "|") For $i = 1 To $aSections[0] - 1 $sName = StringRegExpReplace($aLines[$aSections[$i]], ".*:(.*),.*", "$1") ConsoleWrite($sName & " - Last Heat: ") $iStart = $aSections[$i + 1] - 1 If $iStart > $aLines[0] Then $iStart = $aLines[0] EndIf For $j = $iStart To $aSections[$i] Step -1 If StringInStr($aLines[$j], "Heat") Then $iHeatNumber = StringRegExpReplace($aLines[$j], ".*Heat\x20(\d+)\x20.*", "$1") ConsoleWrite($iHeatNumber & @CRLF) ExitLoop EndIf Next Next Assumption: The last Heat is always the last listed - if this is not the case the problem become much more complex, although not impossible. Any use? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
deef99 Posted September 15, 2011 Author Share Posted September 15, 2011 (edited) I think this will work most excellently!!! Thank you so much! YUP... just set it up and it ran perfectly! Edited September 15, 2011 by deef99 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