Strings and Numbers

In addition to statements and functions, a macro contains data, or information. For example, if a macro includes a FileOpen statement to open a file, it also needs to know the name of the file to open. The filename is considered to be a piece of information. In WordBasic, information must be in the form of either a string or a number.

Here are some examples of strings and numbers.

Strings

Numbers

"Please type your name"

52.6

"Lucida Sans Type"

.12345678901234

"3,500"

3500

"10"

10


Note that you can include numbers in a string, but WordBasic does not interpret them as numeric values. For example, the string "42" simply represents the characters "4" and "2," not the value 42.

Numbers in WordBasic can include a period as a decimal separator, but not other separators. For example, the number 3,500 generates an error. Note that in WordBasic the decimal separator must be a period, regardless of the decimal separator specified with the International option in Control Panel (Windows) or the keyboard layout specified with the Keyboard control panel (Macintosh).

Note

Large numbers can be expressed as mmmEeee, in which mmm is the mantissa and eee is the exponent (a power of 10). The highest positive number allowed is 1.7976931348623E+308, which represents 1.7976931348623 x 10308. (Technically, WordBasic numbers are double-precision floating-point numbers and occupy 8 bytes of memory.)

Including Quotation Marks and Special Characters in Strings

You can include any character in a string, but double quotation marks and special characters must be handled in a special way. A double quotation mark (") is used to mark the beginning and end of a string, so if you want to include one within a string, you must indicate that it is not intended to end or begin the string. To do so, you use the Chr$() function, which returns a character corresponding to the character code you specify. The code for a double quotation mark is 34. For example, the following instruction assigns the string "The word "cool" appears twice." to the variable result$:

result$ = "The word " + Chr$(34) + "cool" + Chr$(34) + \

" appears twice."

Word provides a shortcut for typing instructions that include quotation marks within strings. If you type two double quotation marks in a row ("") where a double quotation mark should appear within a string, Word splits the string at those places and inserts + Chr$(34) + between each segment when you first run the instruction or save the macro. For example, consider the following line typed in a macro-editing window:

result$ = "The word ""cool"" appears twice."

When you run or save the macro for the first time, Word automatically converts the instruction so it looks like the previous example with Chr$().

You also use Chr$() to include a nonprinting character such as a tab or newline character. For more information, see Chr$() in Part 2, "WordBasic Reference."