Using Multiple Variables with the Same Name
To see how this works, insert two standard modules in a new project and draw three command buttons on a form.
One variable, intX, is declared in the first standard module, Module1. The Test procedure sets its value:
Public intX As Integer ' Declare Module1's intX.Sub Test()
' Set the value for the intX variable in Module1.
intX = 1
End Sub
The second variable, which has the same name, intX, is declared in the second standard module, Module2. Again, a procedure named Test sets its value:
Public intX As Integer ' Declare Module2's intX.Sub Test()
' Set the value for the intX variable in Module2.
intX = 2
End Sub
The third intX variable is declared in the form. module. And again, a procedure named Test sets its value.
Public intX As Integer ' Declare the form's intX' variable.
Sub Test()
' Set the value for the intX variable in the form.
intX = 3
End Sub
Each of the three command buttons' Click event procedures calls the appropriate Test procedure and uses MsgBox to display the values of the three variables.
Private Sub Command1_Click()Module1.Test ' Calls Test in Module1.
MsgBox Module1.intX ' Displays Module1's intX.
End Sub
Private Sub Command2_Click()
Module2.Test ' Calls Test in Module2.
MsgBox Module2.intX ' Displays Module2's intX.
End Sub
Private Sub Command3_Click()
Test ' Calls Test in Form1.
MsgBox intX ' Displays Form1's intX.
End Sub
Run the application and click each of the three command buttons. You'll see the separate references to the three public variables. Notice in the third command button's Click event procedure, you don't need to specify Form1.Test when calling the form's Test procedure, or Form1.intX when calling the value of the form's Integer variable. If there are multiple procedures and variables with the same name, Visual Basic takes the value of the more local variable, which in this case, is the Form1 variable.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/11411056/viewspace-734287/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [轉]Updating Session Variables from Dashboards using Presentation VariablesSession
- Using Multiple Tablespaces (46)
- Under the same directory(folder) copy or rename with the different extension name
- Sessions Get Killed if Connection Use Default Service name (Same as db_name) (Doc ID 730315.1)Session
- How to Set Device Name Using UDEV on Oracle Linux 7.1devOracleLinux
- CMake Error: add_executable cannot create target ““ because another target with the same name已解決Error
- SQL SERVER – Fix: Error Msg 128 The name is not permitted in this context. Only constants, expressions, or variables allowed herSQLServerErrorMITContextExpress
- Cross-Platform DB Migration (same endian) using RMAN Transportable DB-1401921.1ROSPlatform
- Clouse Variables as Inputs
- Variables in Java 變數Java變數
- activiti變數variables變數
- SQL*Plus Substitution VariablesSQL
- Clone a database on the same serverDatabaseServer
- AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhohttpdServerAI
- AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhhttpdServerAI
- Multiple Regression
- MYSQL SHOW VARIABLES簡介MySql
- Type-Checking Variables
- B. Same Parity Summands
- Leetcode Same TreeLeetCode
- [ 答朋友問] same namespace ?namespace
- proxysql global_variables 翻譯SQL
- 異常解決:non-compatible bean definition of same name and class【com.xxx.xxx.XXX】Bean
- [leetcode]same-treeLeetCode
- c++11:std::is_sameC++
- ACM Same binary weightACM
- Leetcode-Same TreeLeetCode
- Same Tree leetcode javaLeetCodeJava
- DB_NAME&TANCE_NAME&DB_UNIQUE_NAME&ORACLE_SID&GLOBAL_NAME&DB_DOMAIN&SERVICE_NAMEOracleAI
- AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::1httpdServerAI
- JavaScript select multipleJavaScript
- Small Multiple(最短路)
- DataGridView with multiple tableView
- Multiple Buffer Pools (83)
- Multiple Block Sizes (53)BloC
- variables_order引數詳解
- TensorFlow入門 - 變數(Variables)變數
- JavaScript30 - 3.CSS VariablesJavaScriptCSS