Dgameman1 Posted February 18, 2014 Share Posted February 18, 2014 (edited) expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.10.2 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here ;$x = 1 ;while $x < 10 Sleep(200) $log = "C:\Users\Daniel\Desktop\log" $lastline = FileReadLine($log, -1) $file = FileOpen($log, 0) $read = FileRead($file) If StringRegExp($lastline, "Start") AND StringRegExp($lastline, "start") Then Send("S") Else ConsoleWrite("Fail" & @LF) EndIf ;$x= $x + 1 ;WEnd ;$hFile = FileOpen($log, 2) ;FileClose($hFile) Edited February 18, 2014 by Dgameman1 Link to comment Share on other sites More sharing options...
kylomas Posted February 18, 2014 Share Posted February 18, 2014 (edited) Try it like this... expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.10.2 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <date.au3> #include <array.au3> ; create some test data local $bGen = false if $bGen then _GenTestData() ; start of your program --------------------------------------------------------------------------- local $st = timerinit() $alog = stringsplit(fileread(@scriptdir & '\test.txt'),@crlf,1) if stringregexp($alog[$alog[0]-1],'(?i)start') then ConsoleWrite('Found start' & @LF) Else ConsoleWrite('Fail' & @LF) endif ConsoleWrite(stringformat('Time to test for string = %2.4f',timerdiff($st)/1000) & @LF) ; end of your program ----------------------------------------------------------------------------- func _GenTestData() local $st = timerinit() filedelete(@scriptdir & '\test.txt') local $aWords = stringsplit(fileread(@scriptdir & '\wordlist.txt'),@crlf,1), $sOut for $1 = 1 to 1000 $sOut &= _now() & ' ' for $2 = 1 to random(10,20,1) $sOut &= ' ' & $aWords[random(0,$aWords[0],1)] Next $sOut &= @CRLF next $sOut &= _now() & ' ' & ' Start' & @crlf filewrite(@scriptdir & '\test.txt',$sOut) ConsoleWrite(stringformat('Time to gen test data = %2.4f',timerdiff($st)/1000) & @LF) endfunc kylomas Edited February 18, 2014 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Dgameman1 Posted February 18, 2014 Author Share Posted February 18, 2014 Woah woah, there's no simple fix for my code?? Link to comment Share on other sites More sharing options...
kylomas Posted February 18, 2014 Share Posted February 18, 2014 (edited) Yes...can you explain the $file and $read variables? edit: and the sleep? Edited February 18, 2014 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted February 18, 2014 Share Posted February 18, 2014 Try like this (regexp changed)... expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.10.2 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here ;$x = 1 ;while $x < 10 Sleep(200) $log = "C:\Users\Daniel\Desktop\log" $lastline = FileReadLine($log, -1) $file = FileOpen($log, 0) $read = FileRead($file) If StringRegExp($lastline, "(?i)Start") Then Send("S") Else ConsoleWrite("Fail" & @LF) EndIf ;$x= $x + 1 ;WEnd ;$hFile = FileOpen($log, 2) ;FileClose($hFile) Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Dgameman1 Posted February 18, 2014 Author Share Posted February 18, 2014 Why is it that your code worked while mine didn't? If StringRegExp($lastline, "Start") AND StringRegExp($lastline, "start") Then That didn't work, yet If StringRegExp($lastline, "(?i)Start") Then did?? Link to comment Share on other sites More sharing options...
kylomas Posted February 18, 2014 Share Posted February 18, 2014 (edited) because it cannot be both "Start" and "start". The "(?i)" tells the regexp to be case insensitive. edit: what's with the extraneous fileopen, read and sleep? edit2: you could also have used "or" instead of "and" Edited February 18, 2014 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted February 18, 2014 Share Posted February 18, 2014 (edited) FYI, Your script could be reduced to this... #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.10.2 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here $log = @scriptdir & '\test.txt' ( StringRegExp(FileReadLine($log, -1), "(?i)Start") ) ? Send("S") : ConsoleWrite("Fail" & @LF) ;;SSSSS Edited February 18, 2014 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Dgameman1 Posted February 18, 2014 Author Share Posted February 18, 2014 FYI, Your script could be reduced to this... #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.10.2 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here $log = @scriptdir & '\test.txt' ( StringRegExp(FileReadLine($log, -1), "(?i)Start") ) ? Send("S") : ConsoleWrite("Fail" & @LF) ;;SSSSS That seems beautiful except that if I'm looking for the letter S, even if the word has the letter S in it, it catches that =/ Link to comment Share on other sites More sharing options...
kylomas Posted February 18, 2014 Share Posted February 18, 2014 (edited) That seems beautiful except that if I'm looking for the letter S, even if the word has the letter S in it, it catches that =/ and you would expect that if you are looking for the letter S and a word has the letter S in it, not to find it???? edit: and you are introducing additional search criteria... Edited February 18, 2014 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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