Before doing this program, you must apply for variables and define the constants to be used. The variable here is basically the same as the variable we encountered in mathematics. It is a data, but it can be adapted at any time. The constant concept corresponds to the variable. The variable value can be changed during the program running, while the constant
Before doing this program, you must apply for variables and define the constants to be used. The variable here is basically the same as the variable we encountered in mathematics. It is a data, but it can be adapted at any time. The constant concept corresponds to the variable. The variable value can be changed during the program running, while the constant
Before doing this program, you must apply for variables and define the constants to be used.
The variable here is basically the same as the variable we encountered in mathematics. It is a data, but it can be adapted at any time. The constant concept corresponds to a variable. The value of a variable can be changed while the program is running, but the value of a constant remains unchanged.
In the computer, variables and constants must be defined before they are used, otherwise they will be considered invalid characters in the program. In VBA, there are several methods to define variables and constants. First, we can use "Public Const constant name = constant expression" to define a constant, just like
Public const PI = 3.1415926
This statement defines a very common constant. In the future, when we want to use the circumference rate, we only need to replace it with "PI. In this statement, "Public" is used to indicate that the scope of the constant is all the processes of the entire database. If we use "Private" instead, this constant can only be used in the current module. The "Const" statement is used to indicate that the object to be declared is a constant rather than a variable.
The application variable is similar to the application constant. We usually use the "Dim variable As variable type" statement to declare a variable. The role of "Dim" is similar to that of "Const" in the constant application statement, it tells Access that the request is "variable" instead of a constant. For example
Dim number As Integer
That is to say, now we declare a variable of the integer type "number". Later in the program, "number" indicates a variable, instead of a common character combination. A variable can be assigned a new value in a program. The "number = 4" statement is a value assignment statement. In this way, the variable "number" has a value "4 ". if there is another similar statement "number = 3223", the value of the variable "number" will become "3223. Let's take an example:
Public Const PI = 3.141592
DIM a, number As Integer
Number = 159
A = number * 23/PI + 323
In the four statements, the first statement declares a constant "PI", the second statement declares Two integer types of variables "a" and "number", and the third statement is a value assignment statement, assign the variable "number" to the value "159", and the fourth statement is to multiply the value of the variable "number" by "23" and divide it by the constant "PI ", that is, divide by "3.1415926", add "323" to the obtained value, and assign the final value to the variable "".