
Tips.Net > WordTips Home > Creating Macros > Variables > 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
Great Idea! Word is a tool to get what you really want—printed output. This means you need to make sure that Word works as well as possible with your printer, whether it is sitting on your desk or in a room down the hall.
Check out WordTips: Printing and Printers today!
Thousands of WordTips, available for immediate download. Have all the Microsoft Word info you need, right at your fingertips. (more information...)
Ask a Word Question
Make a Comment
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