"
ElseIf Not FileExists(Filename2) Then
MsgBox Filename2 & " does not exist."
Else
Call RunProgram("command /c fc " & filename1 & _
" " & filename2 & " > c:\Users\username\Desktop\temp.txt", True)
Call RunProgram("notepad c:\Users\username\Desktop\temp.txt", False)
End If
Function FileExists(Filename)
Set FileObject = CreateObject("Scripting.FileSystemObject")
FileExists = FileObject.FileExists(Filename)
End Function
Sub RunProgram(Filename, Wait)
Set WshShell = WScript.CreateObject("WScript.Shell")
RetVal = WshShell.Run(Filename, Wait)
End Sub
522 | Chapter 9: Scripting and Automation
Then, using the Call statement, the values you wish to pass to the subroutine
(which are placed in the parameter variables when the script is run)
are listed in parentheses.
This way, the same subroutine or function can be called repeatedly, each
time with one or more different variables. Functions (such as FileExists in
this example) also can return a single variable (usually dependent on the
outcome of some operation).
The first structure defines the FileExists function (discussed later in this
chapter), which is passed a filename and returns a value of True (-1) if the
file exists, and False (0) if it does not. The FileExists function is called
twice, once for each filename entered when the script is run (Filename1 and
Filename2). The If...Then structures (see ???Creating Interactive Scripts with
Conditional Statements,??? earlier in this chapter) first call the function, then
redirect the flow based on the return value (result).
Pages:
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726