MattX Posted January 19, 2005 Share Posted January 19, 2005 About selecting the computers, what about using a list in file? You check the @computername value over the list.I want to take this further if I can. If I create a txt file of computer names how can I tell the script to only do a certain part if the computer exsists in the script - a sort of look up table....I have not done this before so would appreciate some advice. Link to comment Share on other sites More sharing options...
ezzetabi Posted January 19, 2005 Share Posted January 19, 2005 Load the file in a string, convert the string to an array and checks @computername with the list via For loop. Link to comment Share on other sites More sharing options...
MattX Posted January 19, 2005 Author Share Posted January 19, 2005 Load the file in a string, convert the string to an array and checks @computername with the list via For loop.<{POST_SNAPBACK}>Could you provide an example please ? Link to comment Share on other sites More sharing options...
para Posted January 19, 2005 Share Posted January 19, 2005 Simple... RTFM Create a text file. Type in all of your computernames. Read from the text file. Line one, and then + 1, so it goes down the list. $line1 = readtextfile(1) (dont remember exact function name, you get the point) If @ComputerName = $line Then Do whatever you want it to do when it gets it, maybe... Writetotextfile("lol.txt", @Computername & "Working") Hope that helped. -Para Link to comment Share on other sites More sharing options...
MattX Posted January 19, 2005 Author Share Posted January 19, 2005 Does this make any sence to anyone ?; computernames in c:\cnames.txt $cname = FileOpen("C:\cnames.txt", 0) If $cname = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit While 1 $line = FileReadLine($cname) If @error = -1 Then ExitLoop MsgBox(0, "Line read:", $line) Wend If $line = @Computername then DO SOMETHING ELSE DO SOMETHINGELSE FileClose($cname)Would this check the file cnames.txt and if a name was in there that I wanted would execute the If $line=@computername ?Simple...RTFMCreate a text file. Type in all of your computernames.Read from the text file. Line one, and then + 1, so it goes down the list.$line1 = readtextfile(1) (dont remember exact function name, you get the point)If @ComputerName = $line ThenDo whatever you want it to do when it gets it, maybe...Writetotextfile("lol.txt", @Computername & "Working")Hope that helped.-Para <{POST_SNAPBACK}> Link to comment Share on other sites More sharing options...
ezzetabi Posted January 19, 2005 Share Posted January 19, 2005 (edited) This load the whole file in an array, one line per array position. Total lines in position 0. Local $filename = 'test.txt' Local $computerlist, $c If FileExists($filename) Then $computerlist = FileRead($filename, FileGetSize($filename)) Select Case StringInStr($computerlist, @CRLF) StringReplace($computerlist, @CRLF, @LF) Case StringInStr($computerlist, @CR) StringReplace($computerlist, @CR, @LF) EndSelect $computerlist = StringSplit($computerlist, @LF) For $c = 1 To $computerlist[0] MsgBox(0, '', $computerlist[$c]) Next EndIf This one, shown a line per line reading it direcly from the file. Local $filename = 'test.txt' Local $filehandle $filehandle = FileOpen($filename, 0) If $filehandle <> - 1 Then While 1 $line = FileReadLine($filehandle) If @error Then FileClose($filehandle) ExitLoop EndIf MsgBox(0, '', $line) WEnd EndIf Edit: I arrived late. Just fileclose just after the "If @error", not at the end of the script. Leaving handles pending more than needed if a bad idea. Edit2: Download Tidy.exe of Jdbe and try to tidy your script when you do not understand what is going on. Most probably you meant... ; computernames in c:\cnames.txt $cname = FileOpen("C:\cnames.txt", 0) If $cname = -1 Then MsgBox(0, "Error", "Unable to open file.") Else While 1 $line = FileReadLine($cname) If @error Then ExitLoop MsgBox(0, "Line read:", $line) If $line = @ComputerName Then ; DO SOMETHING ExitLoop;so you dont check the rest of the list. Else ; DO SOMETHINGELSE, probably nothing. You have to check the rest of the list. EndIf WEnd FileClose($cname) EndIf Edit3: improved. Edit4: changed the position of FileClose() so it close the handle also when the computername is found. Edited January 20, 2005 by ezzetabi Link to comment Share on other sites More sharing options...
MattX Posted January 19, 2005 Author Share Posted January 19, 2005 Thanks for the reply. When you edited my code you put in:'ExitLoop;so you dont check the rest of the list.'Does that mean not to check the rest of the file if the name is found ?Another question - [ sorry ] - if the computer name is not found in the list will it just execute the rest of the code ?Edit2: Download Tidy.exe of Jdbe and try to tidy your script when you do not understand what is going on. Most probably you meant...; computernames in c:\cnames.txt $cname = FileOpen("C:\cnames.txt", 0) If $cname = -1 Then MsgBox(0, "Error", "Unable to open file.") Else While 1 $line = FileReadLine($cname) If @error = -1 Then FileClose($cname) ExitLoop EndIf MsgBox(0, "Line read:", $line) If $line = @ComputerName Then ; DO SOMETHING ExitLoop;so you dont check the rest of the list. Else ; DO SOMETHINGELSE, probably nothing. You have to check the rest of the list. EndIf WEnd EndIfEdit3: improved.<{POST_SNAPBACK}> Link to comment Share on other sites More sharing options...
ezzetabi Posted January 20, 2005 Share Posted January 20, 2005 Thanks for the reply. When you edited my code you put in:'ExitLoop;so you dont check the rest of the list.'Does that mean not to check the rest of the file if the name is found ?If it is not bleeding obvious, I am afraid you have to script a little more... I'll try to explain with an example:List:ABCDE@Computername = 'C'The script passes the lines of the list reading in order: 'A', 'B', 'C' now it detects that the computer where the script is executing is in the list and do its job. Done the job there is no need of check also the list for reading 'D' and 'E'. It finished already! You need to pass the whole file only if it does not find the @computername in the list.Ops... I noticied that this exitloop will skip the FileClose(), so I changed its position.Another question - [ sorry ] - if the computer name is not found in the list will it just execute the rest of the code ?<{POST_SNAPBACK}>The code that is executed if the @computername is in the list is the one inside the If Then/EndIf with the comment '; DO SOMETHING'. If the whole list passes without finding a match this code is never executed so the script does nothing. Link to comment Share on other sites More sharing options...
MattX Posted January 20, 2005 Author Share Posted January 20, 2005 Thanks - I agree with having to script more. Problem its something I only turn to now and again when I need to find a work around or an answer to a problem. As I am all self taught [ like many others ] I have got loads of bad habits - I really miss my GOTO commands... If it is not bleeding obvious, I am afraid you have to script a little more... I'll try to explain with an example:List:ABCDE@Computername = 'C'The script passes the lines of the list reading in order: 'A', 'B', 'C' now it detects that the computer where the script is executing is in the list and do its job. Done the job there is no need of check also the list for reading 'D' and 'E'. It finished already! You need to pass the whole file only if it does not find the @computername in the list.Ops... I noticied that this exitloop will skip the FileClose(), so I changed its position.The code that is executed if the @computername is in the list is the one inside the If Then/EndIf with the comment '; DO SOMETHING'. If the whole list passes without finding a match this code is never executed so the script does nothing.<{POST_SNAPBACK}> Link to comment Share on other sites More sharing options...
ezzetabi Posted January 20, 2005 Share Posted January 20, 2005 (edited) Oh dear. If you miss goto you REALLY NEED TO SCRIPT MORE. If you want avoid that everyone laught at you, don't say you miss GoTo. But you said so... Scripters -> <- You Edited January 20, 2005 by ezzetabi Link to comment Share on other sites More sharing options...
MattX Posted January 20, 2005 Author Share Posted January 20, 2005 Good lord, I was joking - I've said that before - didn't you spot the after the comment ?BTW - I really miss GOSUB, INKEY$ & DRAW too, but lets not go there...Oh dear. If you miss goto you REALLY NEED TO SCRIPT MORE.If you want avoid that everyone laught at you, don't say you miss GoTo.But you said so...Scripters -> <- You<{POST_SNAPBACK}> Link to comment Share on other sites More sharing options...
ezzetabi Posted January 20, 2005 Share Posted January 20, 2005 You -> <- Scripters. I was joking too... :| Link to comment Share on other sites More sharing options...
MattX Posted January 20, 2005 Author Share Posted January 20, 2005 Oh your such a tease !! God knows what I would do without Autoit though - most of the apps being used at school where I work are launched using it - its a lifesaver. 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