Share this Page URL

A VBA Language Primer > Constants - Pg. 416

Assigning a value to a variable overwrites any previously stored data. An assignment statement consists of the variable name, an equals sign, and the data you want to assign. This can be a value, a calculated value, or another variable (Example 18-7). Example 18-7. Overwriting a Previously Assigned Variable intInteger = 2000 ' assigning an integer value of 2000 intInteger = 5 * 10 ' assigning the result of a multiplication intThis = intThat ' assigning the contents of another variable You can see that assigning numeric values is fairly intuitive. Text and date variables require a bit more explanation. Text values are called strings, and are surrounded by double quotes (Example 18-8). Example 18-8. Assigning a String strVar = "remember this" ' assigning a string to a variable Create a string from smaller strings, or even different data types, by using an am- persand between each piece of data (Example 18-9). Example 18-9. Concatenating Strings ' concatenating strings strMessage = "The color is " & strColor ' concatenating strings and numeric data strMessage = "The price of " & strItem & " is " curPrice