Welcome toWord.Tips.Net
Ask a Word Question
Make a Comment
Learn Access Now
Free Printable Forms
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Legal Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips
Collapsing and Expanding Subdocuments
When programming macros, it is often necessary to determine the result of a status or to set a value. This is most often done with standard values, such as TRUE and FALSE. Over the years, these have developed into generally accepted numeric values on which programmers regularly use. For instance, if you are programming in C or C++, you know that TRUE is a value of -1 and FALSE is a value of 0.
Unfortunately, Word macros have not always been so consistent. Until VBA, there was no consistent definition of TRUE or FALSE. For instance, you can use the following in VBA and get the expected results:
Test = True MsgBox Int(Test)
This displays the value of Test, which has been set to TRUE (-1). Now try the same thing in WordBasic:
Test = True MsgBox Str$(Int(Test))
When you run this, the value 0 is displayed. This is because WordBasic has no pre-defined values for TRUE or FALSE. You can assign these at the beginning of your WordBasic macros so you can then use them in the main body of the macro, as in the following:
TRUE = -1 FALSE = 0
You must be careful, however, that you don't expect WordBasic to always return TRUE or FALSE from functions. Sometimes WordBasic returns 1 for TRUE and sometimes it returns -1, depending on the function being used. VBA is more consistent, with FALSE always being equal to 0 and TRUE always being equal to -1. The following can help you remember the various values for TRUE and FALSE:
| TRUE | FALSE | |||
|---|---|---|---|---|
| WordBasic | 1, -1 | 0 | ||
| VBA | -1 | 0 | ||
| VB | -1 | 0 | ||
| C/C++ | -1 | 0 |
One way around the discrepancy in WordBasic is to never use TRUE, but always use NOT(FALSE).
Tip #124 applies to Microsoft Word versions: 6 95 97 2000 2002 2003
Take Control! Master the real power behind Word! Successfully master the secrets of powerful formatting and create documents that stand out from the rest. Best of all, you can create documents that are easy to maintain and quick to change.