The WIL Tutorial
|
Now, let's look more closely at the line we entered:
Run("C:\Program Files\Microsoft Games\Solitaire\Solitaire.exe", "")
The first part, Run, is a WIL function. As you might have guessed, its purpose is to run a Windows program. There are a large number of functions and commands in WIL, and each has a certain syntax which must be used. The correct syntax for all WIL functions may be found in the WIL Function Reference (Introduction). The entry for Run starts off as follows: Syntax:Run (program-name, parameters) Parameters:(s) program-name the name of the desired .EXE, .COM, .PIF, .BAT file, or a data file.
Like all WIL functions, Run is followed by a number of parameters, enclosed in parentheses. Parameters are simply additional pieces of information which are provided when a particular function is used; they may be either required or optional. Optional parameters are indicated by being enclosed in square brackets. In this case, Run has two required parameters: the name of the program to run, and the arguments to be passed to the program.
|
Note: Strings are delimited by quotes
Note: (s) denotes the parameter requires a string |
WIL functions use several types of parameters. Multiple parameters are separated by commas. In the example
Run("C:\Program Files\Microsoft Games\Solitaire\Solitaire.exe", "")
"C:\Program Files\Microsoft Games\Solitaire\Solitaire.exe" and "" are both string constants. String constants can be identified by the quote marks which delimit (surround) them. You may use either double ("), single forward (') or single back (`) quote marks as string delimiters; the examples in this help file will use double quotes. In our shorthand method for indicating syntax the (s) in front of a parameter indicates that it is a string parameter. You may have noticed how we said earlier that the two parameters for the Run function are required, and yet the entry for Run in the WIL Function Reference describes the second parameter - "parameters" - as being optional. Which is correct? Well, from a WIL language standpoint, the second parameter is required. That is, if you omit it, you will get a syntax error, and your WIL program will halt. However, the program that you are running may not need parameters. Solitaire, for example, does not take parameters. The way we handle this in our programs is to specify a null string - two quote marks with nothing in between - as the second parameter, as we have done in our example above. "C:\Program Files\Microsoft Games\Solitaire\Solitaire.exe" and "" are both string constants. String constants can be identified by the quote marks which delimit (surround) them. You may use either double ("), single forward (') or single back (`) quote marks as string delimiters; the examples in this help file will use double quotes. In our shorthand method for indicating syntax the (s) in front of a parameter indicates that it is a string parameter. You may have noticed how we said earlier that the two parameters for the Run function are required, and yet the entry for Run in the WIL Function Reference describes the second parameter - "parameters" - as being optional. Which is correct? Well, from a WIL language standpoint, the second parameter is required. That is, if you omit it, you will get a syntax error, and your WIL program will halt. However, the program that you are running may not need parameters. Solitaire, for example, does not take parameters. The way we handle this in our programs is to specify a null string - two quote marks with nothing in between - as the second parameter, as we have done in our example above.
|
To illustrate this further, let's create a WIL program containing the following line:
Run("notepad.exe", "")
This is just like our previous file, with only the name of the program having been changed. Save the file, and run it. Is Notepad running? If it is - good. If not, check your script. WinBatch will look for Notepad.exe on the computer's search path. If it isn't there, you may need to locate it with the Windows Explorer. Add a complete pathname to the run statement and the script should work.
|
|
1. Open WinBatch Studio.
2. Type in the line.
|
Now, edit the WIL program as follows:
Run("notepad.exe", "c:\autoexec.bat")
Save the program, exit WinBatch Studio, and run the WIL program again. You should now be in Notepad, with AUTOEXEC.BAT loaded. As we've just demonstrated, Notepad is an example of a program which can be run with or without a file name parameter passed to it by WIL. It can often be helpful to add descriptive text to your WIL programs:
; This is an example of the Run function in WIL Run("notepad.exe", "c:\autoexec.bat")
Note: semi-colons denote comments. The semi-colon at the beginning of the first line signifies a comment, and causes that line to be ignored. You can place comment lines, and/or blank lines anywhere in your WIL programs. In addition, you can place a comment on the same line as a WIL statement by preceding the comment with a semi-colon. For example:
Run("C:\Program Files\Microsoft Games\Solitaire\Solitaire.exe", "") ;this is a very useful function
Everything to the right of a semi-colon is ignored. However, if a semi-colon appears in a string delimited by quotes, it is treated as part of the string.
|