Character Equivalent

Wow! The information in Table 2.2 should trigger an interesting question in your head, which goes something like this. "If binary codes can represent both characters and numbers how do I know what type of data I'm working with?" The notion and application of variables help to answer this question. Variables provide a storage mechanism that accurately manage the binary representations for us. For example, if I store data in an Integer variable, I can feel pretty good VBA will give me back an Integer number. And, if I store data in a String variable, I feel pretty good VBA will give me back characters and not a number. Using built-in VBA functions, it is possible to convert numbers to strings (characters) and strings to numbers.

With the knowledge of how data is represented, it's time to find where and how data is stored. Data can be stored in varying types of media such as volatile memory (also known as random access memory or RAM) and nonvolatile areas such as disk drives. Programmers can easily manage volatile memory areas using variables with languages like VBA. Nonvolatile memory areas such as hard drives are generally managed (stored) in systems such as files or databases like Microsoft Access.

Do not count on VBA to always convert data successfully for you. In fact, it is good programming practice to always use the Val function to convert strings to numbers when performing numeric calculations on string variables or properties.

In addition to variables most programming languages, including VBA, provide support for constants. Unlike variables, constants retain their data values throughout their scope or lifetime.

Constants are useful for declaring and holding data values that will not change during the life of your application. Unless they are declared in a standard code module using the Public keyword, constants cannot be changed once declared.

In VBA, you must use the Const statement to declare a constant as revealed in the next statement, which creates a constant to hold the value of PI.

For readability, I like to capitalize the entire constant name when declaring constants in my VBA code. This way, they really stick out for you and other programmers when seeing their name amongst other variable names in program code.

0 0

Post a comment