定义一个模块级变量 bQuit As Boolean'当单击菜单中的 mnuExit 时Private Sub mnuExit_Click() bQuit = True Unload Me End SubPrivate Sub Form_Unload(Cancel As Integer) if bQuit Then ' 退出代码 Else Cancel = 1 EndIf End Sub
定义一个模块级变量 bQuit As Boolean'当单击菜单中的 mnuExit 时Private Sub mnuExit_Click() bQuit = True Unload Me End SubPrivate Sub Form_Unload(Cancel As Integer) if bQuit Then ' 退出代码 Else Cancel = 1 Me.Hide EndIf End Sub
尽量用Unload Me 不要用End
YanJieBing(小严) 说对了可是我就是:' 退出代码写不好,又会返回到Private Sub mnuExit_Click() bQuit = True Unload Me End Sub这个函数中去,也就是退不出来了
我在模块在这样定义:Dim bQuit As Boolean在窗体中怎么会说bQuit没有定义呢
我在模块中这样定义:Dim bQuit As Boolean在窗体中怎么会说bQuit没有定义呢
To ysp128(世纪梦),用Public bQuit As Boolean
To ysp128(世纪梦),用Public bQuit As Boolean
To ysp128(世纪梦):用Public bQuit As Boolean!
哦!谢谢但还是不会退出程序返回到下面函数中去了,无返回值的语句是什么呢? Private Sub mnuExit_Click() bQuit = True Unload Me End Sub
首先我要讲一下模块是一个 Module ,其中的变量要在窗体中引用时,必须定义为 Public 或 Global而模块级变量 则是指 在一个窗体、类、或模块中定义的变量用 Dim 定义后只能在本窗体、本类、本模块在使用,用 Public 定义后,可以在其他窗体、类、模块中使用如窗体 frmShow 中有一模块级变量 Public m As Interger 则引用为: frmShow.m如以 Dim m As Integer 形式定义,则在外部将不可显示
在退出代码中,可不能再调用 mnuExit_Click 过程了,否则就会进入死锁。
用unload不行吗?这个不能满足你的要求?
用QueryUnload事件来判断退出的模式,通过判断UnloadMode得值来判断程序的退出方式Private Sub Command1_Click() Unload Me End SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If UnloadMode = 0 Then Cancel = 1 'Me.Hide End If End Sub
定义一个模块级变量 bQuit As Boolean'当单击菜单中的 mnuExit 时Private Sub mnuExit_Click() bQuit = True Unload Me End SubPrivate Sub Form_Unload(Cancel As Integer) if bQuit Then ' 退出代码 Else Cancel = 1 Me.Hide EndIf End Sub
hide "就是隐藏
end
sub end
bQuit = True
Unload Me
End SubPrivate Sub Form_Unload(Cancel As Integer)
if bQuit Then
' 退出代码
Else
Cancel = 1
EndIf
End Sub
bQuit = True
Unload Me
End SubPrivate Sub Form_Unload(Cancel As Integer)
if bQuit Then
' 退出代码
Else
Cancel = 1
Me.Hide
EndIf
End Sub
不要用End
bQuit = True
Unload Me
End Sub这个函数中去,也就是退不出来了
Private Sub mnuExit_Click()
bQuit = True
Unload Me
End Sub
首先我要讲一下模块是一个 Module ,其中的变量要在窗体中引用时,必须定义为 Public 或 Global而模块级变量 则是指 在一个窗体、类、或模块中定义的变量用 Dim 定义后只能在本窗体、本类、本模块在使用,用 Public 定义后,可以在其他窗体、类、模块中使用如窗体 frmShow 中有一模块级变量 Public m As Interger 则引用为: frmShow.m如以 Dim m As Integer 形式定义,则在外部将不可显示
在退出代码中,可不能再调用 mnuExit_Click 过程了,否则就会进入死锁。
Unload Me
End SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = 0 Then
Cancel = 1
'Me.Hide
End If
End Sub
bQuit = True
Unload Me
End SubPrivate Sub Form_Unload(Cancel As Integer)
if bQuit Then
' 退出代码
Else
Cancel = 1
Me.Hide
EndIf
End Sub