Agent Orange Posted September 21, 2006 Share Posted September 21, 2006 I need to grab a line of text from a text file copy that data into a variable...use that variable then loop around grab the very next line from that text file copy it into the variable and use it in the loop....doing this over and over again until it has gone through all the lines of text....any ideas? Thanks Link to comment Share on other sites More sharing options...
extra Posted September 21, 2006 Share Posted September 21, 2006 I need to grab a line of text from a text file copy that data into a variable...use that variable then loop around grab the very next line from that text file copy it into the variable and use it in the loop....doing this over and over again until it has gone through all the lines of text....any ideas?ThanksSorry for this little out of subject, but does my name make sense for u Agent ?eX Link to comment Share on other sites More sharing options...
Agent Orange Posted September 21, 2006 Author Share Posted September 21, 2006 Sorry for this little out of subject, but does my name make sense for u Agent ?eXNo Link to comment Share on other sites More sharing options...
xcal Posted September 21, 2006 Share Posted September 21, 2006 (edited) Maybe this'll help... #include <File.au3> Dim $a_file, $x Func search() _FileReadToArray(@ScriptDir & '\your.txt', $a_file) For $i = 1 To $a_file[0] If StringInStr($a_file[$i], 'your_word') Then MsgBox(0, 'Found', 'your_word found on line ' & $i) ExitLoop EndIf Next For $x = $i + 1 To $a_file[0] ;edit: added + 1 so it starts at the next line MsgBox(0, 'Next Lines', $a_file[$x]) Next EndFunc Edited September 21, 2006 by xcal How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
Agent Orange Posted September 21, 2006 Author Share Posted September 21, 2006 (edited) Maybe this'll help... #include <File.au3> Dim $a_file, $x Func search() _FileReadToArray(@ScriptDir & '\your.txt', $a_file) For $i = 1 To $a_file[0] If StringInStr($a_file[$i], 'your_word') Then MsgBox(0, 'Found', 'your_word found on line ' & $i) ExitLoop EndIf Next For $x = $i + 1 To $a_file[0] ;edit: added + 1 so it starts at the next line MsgBox(0, 'Next Lines', $a_file[$x]) Next EndFunc Xcal- Thanks for the response. When I try this code modified to work in my situation I don't get any values returned when I test that $a_file variable. There is nothing in it. Any ideas Edited September 21, 2006 by Agent Orange Link to comment Share on other sites More sharing options...
xcal Posted September 21, 2006 Share Posted September 21, 2006 (edited) $a_file will actually be an array of the file separated line by line. $a_file[0] is total lines $a_file[1] is line 1 $a_file[2] is line 2 $a_file[3] is line 3 and so on... The first loop in the function is exited when it finds the line with your search word, so, when that first loop is exited, $i is the first line to start whatever you want to do. $i + 1 is where to start working for the next loop, which is the next line. $x is the iteration of the second loop. So, $a_file[$x] is all the following lines while in that loop. I hope that somehow makes sense. I'm taking painkillers for a bad tooth right now haha... edit I think this looks better, actually... #include <File.au3> Dim $a_file, $x Func search() _FileReadToArray(@ScriptDir & '\your.txt', $a_file) For $i = 1 To $a_file[0] If StringInStr($a_file[$i], 'your_word') Then ExitLoop Next For $x = $i To $a_file[0] MsgBox(0, 'The Lines', $a_file[$x]) ;*note Next EndFunc * do your stuff here. $a_file[$x] starts at the first line found by your_word (some search word indicating this is the line you want to start at), and loops to the end of the array (last line). Make changes in the array, then write it back to the file, if you want. Edited September 21, 2006 by xcal How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
Agent Orange Posted September 21, 2006 Author Share Posted September 21, 2006 Xcal- Thanks again for your help. I still can't seem to get it to work. If I put a number...for example MsgBox(0, 'Next Lines', $a_file[$1])....it returns the proper text line. If I don't it returns a number 477 Here is what I have #include <File.au3> Dim $a_file, $x, $sFilePath, $i _FileReadToArray('f:\selist.txt', $a_file) For $i = 1 To $a_file[0] If StringInStr($a_file[$i], '') Then ExitLoop Next Run("C:\Program Files\Knowlix\IKnowAuthor.exe","",@SW_MAXIMIZE) MsgBox(0,"test",$a_file[$x]) sleep(40000) MsgBox(0,"test","",$a_file[$x]) WinWaitActive("KnowlixAuthor") ControlSend("KnowlixAuthor","","TEdit1",$a_file[$x]) Sleep(400) ControlClick("KnowlixAuthor","","TButton1") sleep(1500) Send("{TAB}") Send("!f") Send("p") sleep(900) Sleep(1500) ControlClick("Print","","TButton2") WinWaitActive("Save PDF File As") FileChangeDir("F:\iknow_pdfs\SE\") Send("f:\iknow_pdfs\SE\" & $a_file[$x]) Sleep(200) ControlClick("Save PDF File As","","Button2") WinWaitActive("Adobe Acrobat Professional") Send("^q") ;closes acrobat Send("!f") Send("x") sleep(300) WinWaitActive("KnowlixAuthor") Send("!f") Send("x") Send("!f") Send("x") For $x = $i To $a_file[0] MsgBox(0, 'Next Lines', $a_file[$x]) Next Link to comment Share on other sites More sharing options...
xcal Posted September 21, 2006 Share Posted September 21, 2006 (edited) Try this... note the problem: expandcollapse popup#include <File.au3> Dim $a_file, $sFilePath, $i _FileReadToArray('f:\selist.txt', $a_file) For $i = 1 To $a_file[0] If StringInStr($a_file[$i], '') Then ExitLoop ;<== * problem Next Run("C:\Program Files\Knowlix\IKnowAuthor.exe", "", @SW_MAXIMIZE) MsgBox(0, "test", $a_file[$i]) Sleep(40000) MsgBox(0, "test", "", $a_file[$i + 1]) WinWaitActive("KnowlixAuthor") ControlSend("KnowlixAuthor", "", "TEdit1", $a_file[$i + 2]) Sleep(400) ControlClick("KnowlixAuthor", "", "TButton1") Sleep(1500) Send("{TAB}") Send("!f") Send("p") Sleep(900) Sleep(1500) ControlClick("Print", "", "TButton2") WinWaitActive("Save PDF File As") FileChangeDir("F:\iknow_pdfs\SE\") Send("f:\iknow_pdfs\SE\" & $a_file[$i + 3]) Sleep(200) ControlClick("Save PDF File As", "", "Button2") WinWaitActive("Adobe Acrobat Professional") Send("^q") ;closes acrobat Send("!f") Send("x") Sleep(300) WinWaitActive("KnowlixAuthor") Send("!f") Send("x") Send("!f") Send("x") ;That line needs a way to know where to start from. '' is nothing (anything in this case), so it'll exit the loop immediately. Put in some key text: 'start line always contains this text' edit - added in the + 1, + 2, + 3... I'm assuming you want those to be the lines following your first one. Removed the second ($x) loop, since it looks like you don't need that. another edit - btw, I've been assuming that the first line you want to start from isn't on line 1. Is this correct? Edited September 21, 2006 by xcal How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
Agent Orange Posted September 21, 2006 Author Share Posted September 21, 2006 Xcal- That worked! Thanks Link to comment Share on other sites More sharing options...
xcal Posted September 21, 2006 Share Posted September 21, 2006 Xcal-That worked! ThanksNo problem. Was much easier after seeing your code. How To Ask Questions The Smart Way 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