bottom
Great WordTips!
         
Your e-mail address is safe!
Close Note

Tips.Net > WordTips Home > Macros > Compatibility Between VBA and WordBasic > When True is Not True

When True is Not True

Summary: An examination of different ways that True and False values are handled in VBA and WordBasic. (This tip works with Microsoft Word 6, Word 95, Word 97, Word 2000, Word 2002, and Word 2003.)

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


More Power! For some people, the prospect of creating Word macros can be scary. WordTips: The Macros can help you conquer your fears and you'll discover you're much more confident and productive as you make Word do exactly what you want. This is an invaluable source for learning macros. You are introduced to the topic in bite-sized chunks, pulled from past issues of WordTips. Learn at your own pace, exactly the way you want.
 
Check out WordTips: The Macros today!

Helpful Links

Ask a Word Question
Make a Comment

Tips.Net Home
Tips.Net Store

WordTips FAQ
WordTips Premium

Learn Access Now

Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips

Advertise on the
WordTips Site

 

Great Info!

Get tips like this every week in WordTips, a free productivity newsletter. Enter your e-mail address and click "Subscribe."
     
(Your e-mail address will never be shared with anyone, ever.)