-
What does automatic, manual mean.
-
Question 1: When addressing, because the address of the variable is passed directly to the parameter, the size and type of the two memory addresses are involved, so if the types do not match, an error message will be generated. For passing values, there is no such limitation, because all you pass is the "value".
But passing a value doesn't mean that you won't produce an error, for example
dim x as string
x = "a"
sub proc(byval a as integer)
So: call proc(x).
In this case, a type mismatch error will occur. Since argument a is an integer variable, if you assign a string variable to it you will produce an error, which is the same as the definition of a mismatch of your variable type, for example.
dim x as integer
x = "a"
This can also produce a type mismatch error.
Therefore, correctly defining variables and parameter types is one of the good habits of VB programming!! If you stick to the rules, you won't be able to make mistakes!
Q2: Regarding module-level variables, their scope is the entire module, and the variable disappears when the module is unloaded or exited. Let's start by simplifying yours:
private x as string
private sub command1_click()
x = 5end sub
private sub proc(byval a as integer, byval b as integer)
msgbox x
x = 5 * x
msgbox x
end sub
With the ** above, we can get a pop-up window that shows a result of 5. The result is 25, which is the result of constantly calling and modifying module-level variables.
I know your actual question is the difference between byref and byval, you can see the example I answered in the past
-
After option explicit is written on the first line in the original document, all variables will be forcibly checked for declaration.
1: If the data type does not match, there will be a prompt when the parameters are passed, but when it is declared as a variant, it will not.
2: Variable declaration method: keywords: dim, private, public
1:DIM is suitable for, forms, procedures, functions, and variables are declared.
dim a as string
When declared in the form, it is placed at the top of all **. This variable is available in all procedures and functions in this form, but is not accessible in other forms. This is a form-level variable.
private sub main() or in the function ( private function moveobject().
dim a as string 'This A variable is the same as the A above. However, the scope of application is different. It only applies in this process or in a function.
There is no conflict with Form A. This is the process variable.
end sub
public a as string
This variable declaration is made in the standard module. It can be used and accessed by processes, functions, variables, and throughout the system. Its value can also change at any time during use. These are global variables.
Marriage StarThe position means that you are about to find your other half or ready to get married, anyway, it is a representative of marriage. The marriage planet in the 6th house may be from work partners, but they are not in order. The boy was very devoted to his work, and his wife had a hard time choosing the boy herself. >>>More
Your first one is not a loop statement.
private sub form_click()if i = 0 then >>>More
Expense accounts include:
Cost class. 5001 Production Costs The production costs incurred by the enterprise in carrying out industrial production. >>>More
Novice makeup first moisten**, first apply the foundation evenly to the face with your hands, then apply the BB cream to the face, then apply the double eyelid patch, choose your favorite color for the eyeshadow part, then apply blush, and finally set the makeup with loose powder. >>>More
After opening the error, VB will generate a log file in the same directory, open it with Notepad, and see the name of the control you don't have. Re-open VB, not open the project just now! Check"parts"There are no of those controls in the dialog. >>>More