Jump to content

Recommended Posts

Posted

I am trying to do a find replace in a file using notepad, however the files I want to change are on other machines. If a machine is not turned on I get a File not found error from notepad. How do I wait for the file to open and if it doesn't the continue processing the next file on another computer? This is what I've done

$i=301

$file = FileOpen("d:\dostuff\network\complist.txt", 0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

; Read in lines of text until the EOF is reached

while 1

for $count = $i to 331

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

Run("Notepad.exe", "", @SW_MAXIMIZE)

WinWaitActive("Untitled -")

Send("^o")

WinWaitActive("Open")

sleep(1000)

Send("^a")

send($line)

send("{enter}")

winwaitactive ("environ.ccc - Notepad"),"",10

if winexists ("open", "File not found.") then

send("{space}")

send("!{f4}")

send("!{f4}")

FileWriteLine ("c:\log.txt", "error on computer: " & $line & @crlf )

next

endif

;start to edit if file exists

send("^h")

WinWaitActive("Replace")

send("998")

send("{tab}")

send($i)

send("{TAB 4}")

send("{space}")

send("{TAB}")

send("{space}")

send("^s")

send("!{f4}")

next

Wend

FileClose($file)

The red NEXT hasd no corresponding for it says, so how do I jump out of the loop and continue with the next computer whithout processing all the purple section? Help I've got goto withdrawl symptoms!

BTW how do I post code in one of them code boxes on the forum?

Posted (edited)

try:

$i = 301
$file = FileOpen("d:\dostuff\network\complist.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached

While 1
    For $count = $i To 331
        $line = FileReadLine($file)
        
        If @error = -1 Then ExitLoop
        Run("Notepad.exe", "", @SW_MAXIMIZE)
        WinWaitActive("Untitled -")
        Send("^o")
        WinWaitActive("Open")
        Sleep(1000)
        Send("^a")
        Send($line)
        Send("{enter}")
        WinWaitActive("environ.ccc - Notepad"), "", 10
        If WinExists("open", "File not found.") Then
            Send("{space}")
            Send("!{f4}")
            Send("!{f4}")
            FileWriteLine("c:\log.txt", "error on computer: " & $line & @CRLF)
            ContinueLoop
        EndIf
        
  ;start to edit if file exists
        Send("^h")
        WinWaitActive("Replace")
        Send("998")
        Send("{tab}")
        Send($i)
        Send("{TAB 4}")
        Send("{space}")
        Send("{TAB}")
        Send("{space}")
        Send("^s")
        Send("!{f4}")
    Next
WEnd
FileClose($file)

ContinueLoop is the word you were looking for i think.

EDIT: BTW: Why do you have an endless loop around it?

Edited by ZeDMIN
Posted

  "BTW: Why do you have an endless loop around it?"

err guess that would be the "while 1" line I'm not sure I'm just copy and paste programming at the mo whilst I get my head around V3.

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
×
×
  • Create New...