新手,编程中遇到一个,我的程序中用了一个command1的按钮,用于退出程序。在退出程序前时需要做一些我需要的工作例如:
......
......
...... '这是我退出程序前需要运行的
End '最后再退出
但是如果用户点右上角窗体的叉叉,程序就自动退出了。而达不到我的需要。请教如何才能点右上叉叉时实现我的需求?谢谢。
......
......
...... '这是我退出程序前需要运行的
End '最后再退出
但是如果用户点右上角窗体的叉叉,程序就自动退出了。而达不到我的需要。请教如何才能点右上叉叉时实现我的需求?谢谢。
解决方案 »
- microsoft activex data objects 2.8 和 6.0 哪版本个新
- 刚学VB的小菜
- ActiveReports问题
- 使用可视化数据管理器时出现这种现象:
- Ado.RecordSet的问题
- 怎样操作窗体样式中WS_SYSMENU里得选项,比如要去掉SYSMENU里得关闭选项!
- 各位前辈帮我提供一个初学者学习网络编程的书吧。
- 不知道对方的IP,那怎么用WINSOCK来连接对方(20分)
- 请专家帮忙呀!!!!!急!!!!
- ADO中如何如用Edit?
- shellexecute调用 powerpoint文件问题--(急!!!!在线等待!!!!!)
- VB中打开word,第一次可以打开,第二次就打不开了。
......
......
...... '这是我退出程序前需要运行的
End Sub
Dim i%
For i = 0 To 3
Debug.Print i
Next
MsgBox "做完上面的事就退出!"
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim Msg ' Declare variable.
If UnloadMode > 0 Then
' If exiting the application.
Msg = "Do you really want to exit the application?"
Else
' If just closing the form.
Msg = "Do you really want to close the form?"
End If
' If user clicks the No button, stop QueryUnload.
If MsgBox(Msg, vbQuestion + vbYesNo, Me.Caption) = vbNo Then Cancel = True
End Sub参看MSDN帮助:
———————————————————————Visual Basic ReferenceQueryUnload Event
Occurs before a form or application closes. When an MDIForm object closes, the QueryUnload event occurs first for the MDI form and then in all MDI child forms. If no form cancels the QueryUnload event, the Unload event occurs first in all other forms and then in an MDI form. When a child form or a Form object closes, the QueryUnload event in that form occurs before the form's Unload event.SyntaxPrivate Sub Form_QueryUnload(cancel As Integer, unloadmode As Integer)Private Sub MDIForm_QueryUnload(cancel As Integer, unloadmode As Integer)The QueryUnload event syntax has these parts:Part Description
cancel An integer. Setting this argument to any value other than 0 stops the QueryUnload event in all loaded forms and stops the form and application from closing.
unloadmode A value or constant indicating the cause of the QueryUnload event, as described in Return Values.
Return ValuesThe unloadmode argument returns the following values:Constant Value Description
vbFormControlMenu 0 The user chose the Close command from the Control menu on the form.
vbFormCode 1 The Unload statement is invoked from code.
vbAppWindows 2 The current Microsoft Windows operating environment session is ending.
vbAppTaskManager 3 The Microsoft Windows Task Manager is closing the application.
vbFormMDIForm 4 An MDI child form is closing because the MDI form is closing.
vbFormOwner 5 A form is closing because its owner is closing.
These constants are listed in the Visual Basic (VB) object library in the Object Browser.ResThis event is typically used to make sure there are no unfinished tasks in the forms included in an application before that application closes. For example, if a user has not yet saved some new data in any form, your application can prompt the user to save the data.When an application closes, you can use either the QueryUnload or Unload event procedure to set the Cancel property to True, stopping the closing process. However, the QueryUnload event occurs in all forms before any are unloaded, and the Unload event occurs as each form is unloaded.
Command1_Click
End Sub
Dim X As String
X = MsgBox("你确定要退出系统吗?", vbYesNo, "提示信息")
Select Case X
Case 6
Case 7
End
End Select
End Sub不管是点击“是”或“否”,都退出程序。而这段代码在command1中使用正常。点“是”退出,点“否”不退出。这是为什么呢?
Private Sub Form_Unload(Cancel As Integer)
Dim X As String
X = MsgBox("你确定要退出系统吗?", vbYesNo, "提示信息")
Select Case X
Case 6
End
Case 7
Cancel = True
End Select
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim X As String
X = MsgBox("你确定要退出系统吗?", vbYesNo, "提示信息")
Select Case X
Case 7
Case 6
End
End Select
End Sub
还是出现点击“是”或“否”,都退出程序。而这段代码在command1中使用正常。点“是”退出,点“否”不退出。这是为什么呢?高手们帮我想想办法啊?