These are mostly used in Conditional statements (IF THEN ELSE), which will be discussed shortly.
Often times you will want to combine strings together, a process called concatenation. You concatenate strings together in VB with the ampersand character (&). The following code combines two strings together, with a space added in between:
Often times you will have to convert values in order to work with them better. This might mean converting a decimal number into a whole number, or a numerical sequence into a string. You can do this through several conversion functions that are built into VBA. There are many conversion functions, and we will not cover all of them in this supplement. We will only look at two functions, CInt and CStr.
The CInt function will convert a number variant into an integer and rounds it to the nearest even number. The CStr function will convert an integer into a string subtype.
Variables can be either local or global in scope. The variables we have seen so far have been global in nature, that is, they are valid for the entire block of code that we have written. Sometimes you may wish to break your code into functions or procedures, which are blocks of code that you can reuse throughout your application. In this case, if you declare a variable in a procedure or a function, the variable is only valid for the time that the procedure or function is executed.
Global variables must be defined at the top of the module before any subroutines or functions are defined.
This exercise will demonstrate local variables that are used in sub-procedures.
Define the global variable. This must be done outside of any subroutine or function and must be defined at the top of the module before any subroutines or functions are defined