locutus243 Posted January 4, 2006 Posted January 4, 2006 Hiya guys, HAPPY NEW YEAR to all. I have a problem that I'm guessing as usual is easy but nevertheless I'm stumped! I've tried to give a simply example of whats going wrong... I'm writing records to a text file using FileWriteLine. Say it has the following records:- Liverpool Man Utd Barcelona Real Madrid Liverpool Arsenal Spurs Then using FileRead I am retrieving information underneath my specified search. (So if I search for Man Utd, FileReadLine will return 'Barcelona') I then use this information in a table which displays the information (in this case 'Barcelona')! However if I search for Liverpool, because it appears twice in my text file, it returns 'Man Utd' and then 'Arsenal'. And its only Arsenal that I manage to return to my table (using $var = FileReadLine($file)) How can I work it so that I can capture the line after each time Liverpool appears. So Man Utd will the result of one variable and Arsenal te result of the other??? Hope you see what I mean, I'm not sure I've explained it too well. Would appreciate any help! Cheers guys Mark P.S. If you cant understand my rubbish explanation then let me know and I'll try to make it clearer rather than just ignoring the post entirely.
ChrisL Posted January 4, 2006 Posted January 4, 2006 You've lost me.. posting your code may help to understand what it is your doing [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
locutus243 Posted January 4, 2006 Author Posted January 4, 2006 expandcollapse popup$file = FileOpen("test.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $number = 1 ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop If $line = "Liverpool" Then $read = FileReadLine($file) EndIf Wend FileClose($file) #include <GuiConstants.au3> ; GUI GuiCreate("Sample GUI", 400, 400) GuiSetIcon(@SystemDir & "\mspaint.exe", 0) ; LIST GuiCtrlCreateList("", 5, 190, 100, 90) GuiCtrlSetData(-1, "a.Sample|b.List|c.Control|d.Here", "b.List") ; LIST VIEW $listView = GuiCtrlCreateListView("Club|ListView|", 110, 190, 110, 80) GuiCtrlCreateListViewItem($read1 & "|One", $listView) ; GUI MESSAGE LOOP GuiSetState() While GuiGetMsg() <> $GUI_EVENT_CLOSE WEnd Hey Chris, Thanks for letting me know my explanation was useless, I thought it may be the case! As you can see from above, I am using a FileReadLine function at the top to get my data from my text file (using 'If you find this then I want the next line' in my IF function) and then creating a Gui at the bottom to display this data! Normally this works fine, however if the value I'm looking for appears more than once in my list then I want it to return the first value as $read1, the second as $read2 etc.... Rather than my Gui only being able to show the last instance. I don't know if this is any clearer, it feels as clear as mud to me. Perhaps with the football team example I gave in my first post you'll understand what I mean??? Cheers Mark And if you want me to hav another bash at explaining it I will gladly, cos its doing my head in at the moment!!!!
seandisanti Posted January 4, 2006 Posted January 4, 2006 expandcollapse popup$file = FileOpen("test.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $number = 1 ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop If $line = "Liverpool" Then $read = FileReadLine($file) EndIf Wend FileClose($file) #include <GuiConstants.au3> ; GUI GuiCreate("Sample GUI", 400, 400) GuiSetIcon(@SystemDir & "\mspaint.exe", 0) ; LIST GuiCtrlCreateList("", 5, 190, 100, 90) GuiCtrlSetData(-1, "a.Sample|b.List|c.Control|d.Here", "b.List") ; LIST VIEW $listView = GuiCtrlCreateListView("Club|ListView|", 110, 190, 110, 80) GuiCtrlCreateListViewItem($read1 & "|One", $listView) ; GUI MESSAGE LOOP GuiSetState() While GuiGetMsg() <> $GUI_EVENT_CLOSE WEnd Hey Chris, Thanks for letting me know my explanation was useless, I thought it may be the case! As you can see from above, I am using a FileReadLine function at the top to get my data from my text file (using 'If you find this then I want the next line' in my IF function) and then creating a Gui at the bottom to display this data! Normally this works fine, however if the value I'm looking for appears more than once in my list then I want it to return the first value as $read1, the second as $read2 etc.... Rather than my Gui only being able to show the last instance. I don't know if this is any clearer, it feels as clear as mud to me. Perhaps with the football team example I gave in my first post you'll understand what I mean??? Cheers Mark And if you want me to hav another bash at explaining it I will gladly, cos its doing my head in at the moment!!!!try this... #include<file.au3> dim $contents _FileReadToArray("test.txt",$contents) $ToBeReturned = "" for $x = 1 to $contents[0] If $contents[$x] = "Liverpool" Then $ToBeReturned = $ToBeReturned & "|" & $contents[$x+1] Next #include <GuiConstants.au3> ; GUI GuiCreate("Sample GUI", 400, 400) GuiSetIcon(@SystemDir & "\mspaint.exe", 0) ; LIST $thelist = GuiCtrlCreateList("", 5, 190, 100, 90) GuiCtrlSetData($thelist, $ToBeReturned, "like this?") ; LIST VIEW $anotherexample = StringSplit($ToBeReturned,"|") $listView = GuiCtrlCreateListView("Club|ListView|", 110, 190, 110, 80) For $y = 1 to $anotherexample[0] GuiCtrlCreateListViewItem($anotherexample[$y],$listView) Next ; GUI MESSAGE LOOP GuiSetState() While GuiGetMsg() <> $GUI_EVENT_CLOSE WEnd
locutus243 Posted January 5, 2006 Author Posted January 5, 2006 Hey cameronsdad, Once again thankyou immensely for your help. Seems to work well, I appreciate your time and efforts! Best Wishes Mark
locutus243 Posted January 5, 2006 Author Posted January 5, 2006 Hey Cameronsdad, I've been using your code and although it works fine for what it does. I've been trying to make a small modification. With your script I can get the data on the line after the one I specify. But I can't fathom how to get the information from the next two lines, or the next three. In the end I want to use the script to look for a name in the text files and then return the five lines that appear after each instance of that number in my script. Is it possible to do this in the way you have done it using a ReadArray function?? Any help much appreciated Mark
ChrisL Posted January 6, 2006 Posted January 6, 2006 Hey Cameronsdad, I've been using your code and although it works fine for what it does. I've been trying to make a small modification. With your script I can get the data on the line after the one I specify. But I can't fathom how to get the information from the next two lines, or the next three. In the end I want to use the script to look for a name in the text files and then return the five lines that appear after each instance of that number in my script. Is it possible to do this in the way you have done it using a ReadArray function?? Any help much appreciated Mark Try.. for $x = 1 to $contents[0] If $contents[$x] = "Liverpool" Then $ToBeReturned = $ToBeReturned & "|" & $contents[$x+1] & "|" & $contents[$x+2] & "|" & $contents[$x+3] & "|" & $contents[$x+4] & "|" & $contents[$x+5] Next [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
seandisanti Posted January 6, 2006 Posted January 6, 2006 Hey Cameronsdad, I've been using your code and although it works fine for what it does. I've been trying to make a small modification. With your script I can get the data on the line after the one I specify. But I can't fathom how to get the information from the next two lines, or the next three.In the end I want to use the script to look for a name in the text files and then return the five lines that appear after each instance of that number in my script.Is it possible to do this in the way you have done it using a ReadArray function??Any help much appreciatedMarki'm sorry, i swear i typed up a response to this the other day, not sure how it didn't get posted. ChrisL's suggestion is correct, by concatenating in the other elements that you want, and including the delimiter, they'll be added to both the list control and the listview box.
locutus243 Posted January 11, 2006 Author Posted January 11, 2006 Thanks guys, I've managed to use your ideas to do what I want. However now every time I try and run the script it gives me the following error message:- for $x = 1 to $contents[0] for $x = 1 to $contents^ERROR Error: Subscript used with non-Array variable. I've used the function before and it did work fine. I don't understand why it won't work now. Anybody got any suggestions what could be causing this error message?? Thanks Mark
Moderators SmOke_N Posted January 11, 2006 Moderators Posted January 11, 2006 The $contents[0] at that time of run is not in an array... you could protect from a crash like this: If IsArray($contents) Then For $x = 1 To $contents[0] ;stuff you do Next EndIf Or you may choose to replace all the $contents[0]:For $x = 1 To Ubound($contents) - 1 ;stuff you do Next Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
seandisanti Posted January 11, 2006 Posted January 11, 2006 The $contents[0] at that time of run is not in an array... you could protect from a crash like this: If IsArray($contents) Then For $x = 1 To $contents[0] ;stuff you do Next EndIf Or you may choose to replace all the $contents[0]:For $x = 1 To Ubound($contents) - 1 ;stuff you do Nextthat would fix the error, BUT i believe that's a mis-diagnosis, or more accurately a half diagnosis. For whatever reason the FileReadToArray() isn't returning something, maybe the file isn't there or is empty?
Moderators SmOke_N Posted January 11, 2006 Moderators Posted January 11, 2006 that would fix the error, BUT i believe that's a mis-diagnosis, or more accurately a half diagnosis. For whatever reason the FileReadToArray() isn't returning something, maybe the file isn't there or is empty? It wasn't a 'diagnosis' that would imply that I read his/your/their code I was just answering a 'specific' question. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
seandisanti Posted January 11, 2006 Posted January 11, 2006 The $contents[0] at that time of run is not in an array It wasn't a 'diagnosis' that would imply that I read his/your/their code I was just answering a 'specific' question. not a diagnosis? my post was meant to elaborate on yours, not find fault. isn't it a little early for you to be on?
Moderators SmOke_N Posted January 11, 2006 Moderators Posted January 11, 2006 not a diagnosis? my post was meant to elaborate on yours, not find fault. isn't it a little early for you to be on?Not if I hadn't been to bed ... I need to get off this forum! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
seandisanti Posted January 11, 2006 Posted January 11, 2006 Not if I hadn't been to bed ... I need to get off this forum!well now it's too late for sleep, you've signed on for the full shift. the new topics are starting already, get to work!
locutus243 Posted January 13, 2006 Author Posted January 13, 2006 Hey guys, Thanx for your 'diagnosis'? You were right, it was the contents of the file that was causing the problem, it actually didn't have the number of arrays that I was trying to force on it. Cheers Mark
seandisanti Posted January 13, 2006 Posted January 13, 2006 Hey guys, Thanx for your 'diagnosis'? You were right, it was the contents of the file that was causing the problem, it actually didn't have the number of arrays that I was trying to force on it. CheersMarkno problem, always glad to help
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