Word.Tips.Net Welcome toWord.Tips.Net

Helpful Links

Tips.Net Home
WordTips Home

Ask a Word Question
Make a Comment

Tips.Net Store

WordTips FAQ
WordTips Premium

Learn Access Now

Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips

Advertise on the
WordTips Site

Newest Tips

Changing Tabs Using the Ruler

Moving Drawing Objects

Standardizing Note Reference Placement

Selecting Printing of Color Pictures

Stubborn Foreign Languages

Sizing the Preview Pane

Moving Rows and Columns With the Mouse

 

Understanding Variables in WordBasic Macros

Summary: Variables are one of the features of macros that make them powerful and flexible. Learn, through this tip, how WordBasic handles variables. (This tip works with Microsoft Word 6, and Word 95.)

In Word 6 or Word 95, macros are written in a language called WordBasic. This is a specialized version of the BASIC programming language, and as such, allows you to use variables. Variables are nothing but names which represent other data. During the course of your macro you can even change the data to which the name applies.

There are two types of variables you can use in your macros. The first is numeric variables. Numeric variables are designated by names that end in either a number or letter, and can contain numeric data, i.e. numbers. The values assigned to numeric variables can be either whole numbers or numbers that have fractional values, as well. If you are familiar with other programming languages, numeric variables in WordBasic are double-precision, floating-point variables. This means they are accurate to about 15 decimal places.

The other type of variables are string variables. String variables have names that end in a dollar sign, and they can contain any type of text or character you desire. You can assign a maximum of 32,767 such characters to a string variable.

WordBasic also supports the use of variable arrays, which are nothing but entire groups of related data which are referred to by the same variable name. Arrays can be used either for strings or numeric data. For instance, consider the following part of a macro:

Dim Name$(5)
Name$(1) = "Mary"
Name$(2) = "George"
Name$(3) = "Kris"
Name$(4) = "Harry"
Name$(5) = "Anna"

The first line in this code, which uses the Dim statement, declares the array. In this case, the Name$() array is declared to have five elements, numbered 1 through 5. The next five lines assign values to each of the elements in this array. Arrays such as this are helpful when you are processing large amounts of related data. (Purists will point out, however, that under normal circumstances this array will have six elements, since WordBasic starts arrays at 0. Thus, there are elements 0 though 5.)

Tip #117 applies to Microsoft Word versions: 6 | 95

Save Time! WordTips has been published weekly since early 1997. Past issues are available in convenient WordTips archives. Have your own enhanced archive of WordTips at your fingertips, available to use at any time!
 
Check out WordTips Archives today!