home *** CD-ROM | disk | FTP | other *** search
- Bulletin 2 - A discussion of techniques for writing scripts
-
- The following is a discussion about HyperPilot scripts. The purpose of
- this bulletin is to provide you with some application information that may
- not be found in the HyperACCESS/5 manual. These discussions will largely
- be based on question that are frequently asked of our Product Support
- Department. This bulletin will be updated as questions and application
- notes arise. Your contributions and questions are welcome.
-
- Subject: Error checking
-
- Many HyperPilot functions return a TRUE or FALSE result. This result
- can be used to determine the success or failure of a particular
- function. For example, the function: wait text("password:",10) will
- return a TRUE result if the match is successful within 10 seconds,
- otherwise it will return FALSE.
-
- One common mistake is to use these functions without checking the
- return value. A better approach would be to include error processing
- logic to these functions. Look at these two examples:
-
- Case 1: wait text("password:",10)
- prompt("wait text was successful")
-
- Case 2: ifnot wait text("password:",10) branch(100)
- prompt("wait text was successful")
-
- In the first case, if the wait text() function fails, one of two
- outcomes will occur. First, if your script includes a label(990),
- a branch to that label will be executed (more on label(990) later).
- Second, if label(990) does not exist, an error message will appear on
- the Comm screen that points to the offending line in your HyperPilot
- script, and the script ends. If the wait text() function returns a
- TRUE, the next script command is executed.
-
- In the second case, there is no question as to what will happen if
- the wait text() function fails. The script will branch to
- label(100). Again, if the function is successful the next line
- will be executed.
-
- This error trapping becomes very important if you are automating a
- process that is going to be unattended. You don't want an error
- message to appear if nobody is around to clear the message. It's
- also important if you're providing an automated solution for someone
- that may not understand how to recover from such an error.
-
- Although it takes longer to write scripts that contain good error
- checking, in the long run you'll be better off. You don't need
- to perform this error checking on every HyperPilot function that you
- use. Using label(990) along with some of this error checking logic in
- critical places will make for reliable scripts.
-
- Subject: label(990)
-
- You can create a general purpose error trapping routine by using a
- label(990) in you scripts. A branch to this label will take place
- whenever a HyperPilot function that returns a TRUE/FALSE value is
- used without conditional statements (if or ifnot), and that function
- fails. This can provide for an effective method of trapping errors
- without using the 'if' or 'ifnot' conditions on every HyperPilot
- function. Example:
-
- label(100)
- prompt("Running this example will cause a branch to label(990)/r")
- wait match("this will never match", 10)
- prompt("This line should never be displayed")
-
- label(990)
- prompt("A HyperPilot function has failed")
- end()
-
-
- Subject: Variable input through scripts
-
- Learning a command or macro that accepts variable input is a
- snap with HyperACCESS/5. You simply need to use the learning
- options as they appear when you press ALT-L. This is easy if
- you're learning, but not so straight forward if you're writing a
- script. Lets say that in the middle of your script, you wanted
- to go off to the System settings menu and change the baud rate,
- but you didn't want to hard code that rate into the script.
- Instead, you could pause the script at that menu option and
- allow the user of the script to enter the appropriate rate. The
- following demonstrates this approach:
-
- prompt("/nThis displays on the Comm screen, as do all")
- prompt("/nHyperPilot scripts. But the following type")
- prompt("/ncommand will go to the System settings menu")
- prompt("/nand wait for you to enter in a baud rate.")
- wait seconds(10)
- type("<ALT-M>DM<ENTER>R<ALT-L>VKE<ALT-C>")
- prompt("/n/nNow we're back on the Comm screen!")
- end()
-
- The trick here is the ALT-L VKE portion of the type command.
- This tells HA5 to accept (V)ariable input from the (K)eyboard,
- and that (E)nter will terminate the input. The E portion of
- this type command could have also been an 'A'. This would
- have allowed the user to continue working on any of the menus
- (after entering a baud rate), until ALT-R was pressed.
-