hispeed_mike Posted February 13, 2007 Share Posted February 13, 2007 Hi, Below is the code I have been working on. I need to be able to basically read a text file that has windows keys in it. at the end of each of the Serials there is a station number. This script is to basically read that file look at the last two characters then if does not find the match to the input bux ($stid) I need it to move down one line and check again until it find the match, then trim the last two digits and than declare the $stser variable for me to use in the script. I got it to the point of reading and triming the last characters but cannot for the life of me work out the sequence needed to read down the lines until it finds the correct $stid or last 2 didgits. If someone could please help with not just the script but to understand the reason behiind it. That would be great. Thanks again in advance. Mike $compname = InputBox ("Computer Name", "Computer Name shared files are on:", "", "") $locser = InputBox ("Location Name", "Location you are loading:", "", "") $stid = InputBox ("Station Number", "Station Number you are loading:" & @CRLF & "Example:" & @CRLF & "01" & @CRLF & "02" & @CRLF & "." & @CRLF & "." & @CRLF & "." & @CRLF & "10" & @CRLF & "11" & @CRLF & "etc...", "", "") Global $stser $file = "\\" & $compname & "\Clean Install\Windows Serials\" & $locser & ".txt" $string = FileReadLine($file,2) If StringRight ($string, 2) = $stid Then $stser = StringTrimRight ($string, 2) NEED TO WORK OUT LOOP FROM HERE!!! EndIf Link to comment Share on other sites More sharing options...
Zedna Posted February 13, 2007 Share Posted February 13, 2007 $string = StringSplit(FileRead($file),@CRLF,1) For $i = 1 To $string[0] $line = $string[$i] ; do what you want with this line ... Next Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
hispeed_mike Posted February 13, 2007 Author Share Posted February 13, 2007 $string = StringSplit(FileRead($file),@CRLF,1) For $i = 1 To $string[0] $line = $string[$i] ; do what you want with this line ... Next Thanks for the lead.... I inserted it into my script and it reads the first line of the text file but if I enter another value of $stid that would make it move to the next line the script returns nothing. How do I get it to incriment by reading the next line until it finds the last 2 digits in the string match the $stid variable? Here is the two codes combined as I have it. Thanks $compname = InputBox ("Computer Name", "Computer Name shared files are on:", "", "") $locser = InputBox ("Location Name", "Shopping Centre Name you are loading:", "", "") $stid = InputBox ("Station Number", "Station Number you are loading:" & @CRLF & "Example:" & @CRLF & "01" & @CRLF & "02" & @CRLF & "." & @CRLF & "." & @CRLF & "." & @CRLF & "10" & @CRLF & "11" & @CRLF & "etc...", "", "") Global $stser $file = "\\" & $compname & "\Clean Install\Windows Serials\" & $locser & ".txt" $string = FileReadLine($file,2) If StringRight ($string, 2) = $stid Then $stser = StringTrimRight ($string, 2) $string = StringSplit(FileRead($file),@CRLF,1) For $i = 1 To $string[0] $line = $string[$i] ; do what you want with this line ... Next MsgBox ("", "Value Returned", $stser) EndIf All help welcome...If also someone could give me and understanding of the For $i = 1 To string[0] Mike Link to comment Share on other sites More sharing options...
enaiman Posted February 13, 2007 Share Posted February 13, 2007 $string = StringSplit(FileRead($file),@CRLF,1) For $i = 1 To $string[0] $line = $string[$i] ; do what you want with this line ... Next The meaning of this part is; - read the content of the file - store it into an array ($string) - the first element of this array ( $string [0]) holds the number of lines (note the @CRLF the separating character) For $i = 1 To $string[0] -> means starting at 1 (1st line) and ending at $string[0] (last line) $line = $string[$i] -> reads the line content into $line variable ; do what you want with this line ... -> do your job here knowing that $line holds the current line content Next -> tells $i to increment its value and to jump at the begining of the loop Hope it is clear now SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
hispeed_mike Posted February 13, 2007 Author Share Posted February 13, 2007 The meaning of this part is; - read the content of the file - store it into an array ($string) - the first element of this array ( $string [0]) holds the number of lines (note the @CRLF the separating character) For $i = 1 To $string[0] -> means starting at 1 (1st line) and ending at $string[0] (last line) $line = $string[$i] -> reads the line content into $line variable ; do what you want with this line ... -> do your job here knowing that $line holds the current line content Next -> tells $i to increment its value and to jump at the begining of the loop Hope it is clear now Thanks for the explanation. Is there any reason then why the above code is not going to the next line and reading it? Thanks for the heads up. Mike Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 13, 2007 Moderators Share Posted February 13, 2007 Thanks for the explanation. Is there any reason then why the above code is not going to the next line and reading it? Thanks for the heads up. MikeHow do you know it's not? $string = StringSplit(FileRead($file),@CRLF,1) For $i = 1 To $string[0] $line = $string[$i] MsgBox(0, 'Line#' & $i, $line) ; do what you want with this line ... 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. Link to comment Share on other sites More sharing options...
enaiman Posted February 14, 2007 Share Posted February 14, 2007 Thanks for the explanation. Is there any reason then why the above code is not going to the next line and reading it?Thanks for the heads up.MikeMaybe your text file has only 1 line??Don't laugh please ... this could happen sometimes.Sorry if is this a dumb question. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
hispeed_mike Posted February 14, 2007 Author Share Posted February 14, 2007 How do you know it's not? $string = StringSplit(FileRead($file),@CRLF,1) For $i = 1 To $string[0] $line = $string[$i] MsgBox(0, 'Line#' & $i, $line) ; do what you want with this line ... Next $compname = InputBox ("Computer Name", "Computer Name shared files are on:", "", "") $locser = InputBox ("Location Name", "Shopping Centre Name you are loading:", "", "") $stid = InputBox ("Station Number", "Station Number you are loading:" & @CRLF & "Example:" & @CRLF & "01" & @CRLF & "02" & @CRLF & "." & @CRLF & "." & @CRLF & "." & @CRLF & "10" & @CRLF & "11" & @CRLF & "etc...", "", "") Global $stser $file = "\\" & $compname & "\Clean Install\Windows Serials\" & $locser & ".txt" $string = FileReadLine($file,2) If StringRight ($string, 2) = $stid Then $stser = StringTrimRight ($string, 2) $string = StringSplit(FileRead($file),@CRLF,1) For $i = 1 To $string[0] $line = $string[$i] ; do what you want with this line ... Next MsgBox ("", "Value Returned", $stser) EndIf This is the full code I use to test. I have a number of serials in the file all ending in a 2 digit number. The first line of this file has a dumby serial which is all zeros. I cna get this script to miss this frst line and read the next but I I enter the last 2 digits of line 2 it returns nothing back... Thanks for you help Smokn. Mike Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 14, 2007 Moderators Share Posted February 14, 2007 (edited) $compname = InputBox ("Computer Name", "Computer Name shared files are on:", "", "") $locser = InputBox ("Location Name", "Shopping Centre Name you are loading:", "", "") $stid = InputBox ("Station Number", "Station Number you are loading:" & @CRLF & "Example:" & @CRLF & "01" & @CRLF & "02" & @CRLF & "." & @CRLF & "." & @CRLF & "." & @CRLF & "10" & @CRLF & "11" & @CRLF & "etc...", "", "") Global $stser $file = "\\" & $compname & "\Clean Install\Windows Serials\" & $locser & ".txt" $string = FileReadLine($file,2) If StringRight ($string, 2) = $stid Then $stser = StringTrimRight ($string, 2) $string = StringSplit(FileRead($file),@CRLF,1) For $i = 1 To $string[0] $line = $string[$i] ; do what you want with this line ... Next MsgBox ("", "Value Returned", $stser) EndIf This is the full code I use to test. I have a number of serials in the file all ending in a 2 digit number. The first line of this file has a dumby serial which is all zeros. I cna get this script to miss this frst line and read the next but I I enter the last 2 digits of line 2 it returns nothing back... Thanks for you help Smokn. Mike1. Use code tags. 2. With what you have there:$stser = StringTrimRight ($string, 2) $string = StringSplit(FileRead($file),@CRLF,1) For $i = 1 To $string[0] $line = $string[$i] ; do what you want with this line ... Next MsgBox ("", "Value Returned", $stser)oÝ÷ Ø-ëæ¬jëh×6$stser = StringTrimRight ($string, 2) $string = StringSplit(FileRead($file),@CRLF,1) MsgBox ("", "Value Returned", $stser)The For/Next loop isn't even doing anything. Comment through each line of that on what you think it is doing, and you'll probably understand what you need to be doing. Edited February 14, 2007 by SmOke_N 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. Link to comment Share on other sites More sharing options...
nitekram Posted February 14, 2007 Share Posted February 14, 2007 Does this help $compname = InputBox("Computer Name", "Computer Name shared files are on:", "", "") $locser = InputBox("Location Name", "Shopping Centre Name you are loading:", "", "") $stid = InputBox("Station Number", "Station Number you are loading:" & @CRLF & "Example:" & @CRLF & "01" & @CRLF & "02" & @CRLF & "." & @CRLF & "." & @CRLF & "." & @CRLF & "10" & @CRLF & "11" & @CRLF & "etc...", "", "") Global $stser, $line = 1 $file = "\\" & $compname & "\Clean Install\Windows Serials\" & $locser & ".txt" $file = FileOpen($file, 0) While 1 $string = FileReadLine($file) If @error = -1 Then ExitLoop MsgBox(0, "Line read: " & $line, $string) $line = $line + 1 If StringRight($string, 2) = $stid Then $stser = StringTrimRight($string, 2) $string = StringSplit(FileRead($file), @CRLF, 1) ; do what you want with this line ... MsgBox("", "Computer Value Returned", $compname) EndIf WEnd FileClose($file) 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator 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