Guest DaveAvery Posted July 28, 2005 Posted July 28, 2005 I am writing a notepad script that shoud read 80 characters and then insert a CR into the file or hit Enter so that after every 80 characters. A new line is started. After compiling and running the script my computer goes crazy and will not stop. I have posted my script below can someone help me out. Thanks $answer = InputBox("File Name", "Please enter the name of your file","", _ " M") $search = FileFindFirstFile($answer) IF $search = -1 Then MsgBox(0, "Error", "No file match the search pattern") Exit EndIf If 1 Then FileOpen($answer,0) While 1 FileRead($answer, 80) Send("{ENTER}") Wend EndIf WinClose("& $answer &") Send("!y") FileClose($search)
Errorlevel_03 Posted July 28, 2005 Posted July 28, 2005 (edited) I am writing a notepad script that shoud read 80 characters and then insert a CR into the file or hit Enter so that after every 80 characters. A new line is started. After compiling and running the script my computer goes crazy and will not stop. I have posted my script below can someone help me out. Thanks$answer = InputBox("File Name", "Please enter the name of your file","", _" M")$search = FileFindFirstFile($answer)IF $search = -1 ThenMsgBox(0, "Error", "No file match the search pattern")ExitEndIfIf 1 ThenFileOpen($answer,0)While 1FileRead($answer, 80)Send("{ENTER}")WendEndIfWinClose("& $answer &")Send("!y")FileClose($search) <{POST_SNAPBACK}>Try to replace that withLine() Func Line() FileRead($answer, 80) Send("{ENTER}") EndFuncYou also dont need all the extra blue codeWinClose($answer)Hope this helps! Edited July 28, 2005 by Errorlevel_03 I hope you know what a spoiler is...[u]"title WOOPS:Var_start "WOOPS" %0goto Var_"-A true n00b at work[/u]
blindwig Posted July 28, 2005 Posted July 28, 2005 Looking at your code I don't quite get what you're trying to do, but here's some tips: you can replace the whole $search line and IF with this: If Not FileExists($Answer) Then MsgBox(0, "Error", "No file match the search pattern") Exit EndIf And your code, with "IF 1 Then" and your While loop - firstly, there is no reason to do an IF without using a variable, so I'm not sure what you're trying to achieve with that. Secondly, your while loop has no chance to exit, so there is no end to your script, ever. Try this instead: FileOpen($answer,0) FileRead($answer, 80) While Not @Error Send("{ENTER}") FileRead($answer, 80) Wend FileClose($answer) Send("!y") My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions
seandisanti Posted July 28, 2005 Posted July 28, 2005 Try to replace that withLine() Func Line() FileRead($answer, 80) Send("{ENTER}") EndFuncYou also dont need all the extra blue codeWinClose($answer)Hope this helps!<{POST_SNAPBACK}>one thing that both scripts do is open the file for read access and try to write to it. that will not work. The best thing to do in my opinion would be something like this...$thefile = InputBox("File","Enter File Name"); gets input file name and path from user $input = FileOpen($thefile,0);opens specified file $output = FileOpen(StringLeft($input,StringLen($input) - 4) & "o" & StringRight($input,4),1);opens output file, same file name with an 'O' added before the extension if $input = -1 Then;error handling for file open MsgBox(0,"Oops","Failed to open the file") Exit EndIf while 1;loop until we stop it $line = FileRead($input,80);grab your 80 characters if $line = -1 then ExitLoop;stop loop if end of file FileWriteLine($output,$line);writes 80 characters to a line in output file and goes to next line WEnd FileClose($input);close files FileClose($output)
Errorlevel_03 Posted July 28, 2005 Posted July 28, 2005 one thing that both scripts do is open the file for read access and try to write to it. that will not work. The best thing to do in my opinion would be something like this...$thefile = InputBox("File","Enter File Name"); gets input file name and path from user $input = FileOpen($thefile,0);opens specified file $output = FileOpen(StringLeft($input,StringLen($input) - 4) & "o" & StringRight($input,4),1);opens output file, same file name with an 'O' added before the extension if $input = -1 Then;error handling for file open MsgBox(0,"Oops","Failed to open the file") Exit EndIf while 1;loop until we stop it $line = FileRead($input,80);grab your 80 characters if $line = -1 then ExitLoop;stop loop if end of file FileWriteLine($output,$line);writes 80 characters to a line in output file and goes to next line WEnd FileClose($input);close files FileClose($output)<{POST_SNAPBACK}>Ah I see, thanks for the correction! I hope you know what a spoiler is...[u]"title WOOPS:Var_start "WOOPS" %0goto Var_"-A true n00b at work[/u]
seandisanti Posted July 28, 2005 Posted July 28, 2005 Ah I see, thanks for the correction!<{POST_SNAPBACK}>NP, glad i could help
Guest DaveAvery Posted July 28, 2005 Posted July 28, 2005 Thanks everyone for the help I will try and post back when it works. This is a great forum
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