工程菜单->添加模块,然后在模块中用PUBLIC关键字定义 如:PUBLIC a as long 则a始终能够用。
'希望这个对你有点用 Private Sub Command1_Click() Dim Obj As Control For Each Obj In Me '本form Print Obj.Name '打印所有的名称 Next Obj End Sub
Private Sub Command1_Click() Dim Obj As Control Dim pd As Boolean For Each Obj In Me '本form Print Obj.Name '打印所有的名称 If Obj.Name = "Command2" Then pd = True '判断存在Command2否 Next Obj
If pd Then Print "存在Command2" Else Print "不存在Command2" End If End Sub
UP在Modual模块上里用public 定义一个变量就可以在整个工程中应用了 比如:public gCon as new Adodb.connection
如:PUBLIC a as long
则a始终能够用。
Private Sub Command1_Click()
Dim Obj As Control
For Each Obj In Me '本form
Print Obj.Name '打印所有的名称
Next Obj
End Sub
Dim Obj As Control
Dim pd As Boolean
For Each Obj In Me '本form
Print Obj.Name '打印所有的名称
If Obj.Name = "Command2" Then pd = True '判断存在Command2否
Next Obj
If pd Then
Print "存在Command2"
Else
Print "不存在Command2"
End If
End Sub
比如:public gCon as new Adodb.connection