This month you learn how to use the IfThenElse macro, the FileExist macro and also understand how path statements are interpreted by WinHelp systems. First the macro...
The IfThenElse macro is a powerful WinHelp macro. By itself, the macro does very little, but when combined with other macros, IfThenElse can validate conditions and perform specific actions based on true or false conditions.
For example, your Help system may have a link to a spreadsheet file stored externally on the network. Unfortunately, not everyone has access to the network or some users do not have a spreadsheet application installed on their computer. To prevent users that don't have access to the file from receiving errors when they click the link, you could use the IfThenElse macro to determine their accessibility.
If the file is accessible, then the macro records a condition of True and allows you to display the spreadsheet. If the file is inaccessible, then a secondary course of action is taken. You decide what course of action to take -- usually a popup message is sufficient.
This macro looks complicated, but is quite simple, provided you can think logically about what you want it to accomplish.
Let's take a look at the macro
|
|
IfThenElse("marker"/macro, macro1, macro2) |
|
IfThenElse |
This is a Text Marker macro, however we won't use text markers in this example. The macro consists of three macro parameters. |
|
"marker"/macro |
The first parameter validates a condition. It determines whether the condition is true or false. The types of macros you can use to validate a condition are: FileExist, InitMPrint, IsBook, IsMark, IsNotMark, TestALink, and TestKLink In the following example, you use the FileExist macro to determine if a file exists locally or on the network. If the file exists, it returns a value of True and executes the first macro (ExecFile). If the file does not exist or cannot be found, it executes the second macro (PopupId). For example: IfThenElse(FileExist(`budget.xls'),`ExecFile(`budget.xls'),`PopupId(`',`Sorry') The FileExist macro validates the file budget.xls and returns a value of either True or False. |
|
macro1 (if true)
|
If the file exists, it returns True and executes macro1. The following Program macros can be used to launch a program file: For example: IfThenElse(FileExist(`budget.xls'),ExecFile(`budget.xls'),`PopupId(`',`Sorry') |
|
macro2 (if false)
|
If the file does not exist it returns False and executes macro2. If the file cannot be located you should have a secondary course of action to take, such as a popup message or jump to a topic so the dreadful "Topic does not exist" message does not appear. For example: IfThenElse(FileExist(`budget.xls'),ExecFile(`budget.xls'),`PopupId(`',`Sorry')
|