Sign in to follow this  
Followers 0
Guest DaveAvery

Help with Notepad script

7 posts in this topic

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) :)

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 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) :)

<{POST_SNAPBACK}>

Try to replace that with

Line()
Func Line()
FileRead($answer, 80)
Send("{ENTER}")
EndFunc

You also dont need all the extra blue code

WinClose($answer)

Hope this helps!

Edited 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]

Share this post


Link to post
Share on other sites

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")

Share this post


Link to post
Share on other sites

Try to replace that with

Line()
Func Line()
FileRead($answer, 80)
Send("{ENTER}")
EndFunc

You also dont need all the extra blue code

WinClose($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)

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

Ah I see, thanks for the correction!

<{POST_SNAPBACK}>

NP, glad i could help

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Thanks everyone for the help I will try and post back when it works. This is a great forum

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0