简单问题,如何调用 Form_Unload 在线等待

JonyChen2003 2003-10-09 03:00:28


请问如何在一个按钮中实现调用 Form_Unload 函数。谢谢!

我是刚学VB的,所以还请各位帮忙

Private Sub Command1_Click()
Form_Unload
End Sub

Public Sub Form_Unload(Cancel As Integer)
......
......

CloseCQXMapInfoConnection

......
......
End Sub


结果出错!
...全文
375 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jackile 2003-10-11
  • 打赏
  • 举报
回复
Unload me后会自动调用Form_Unload
mooowx 2003-10-11
  • 打赏
  • 举报
回复
100分问这么基础的问题,你太大方了.答案只有一个: Unload me.
学VB,先掌握一些内部函数,会更易上手.
Gelim 2003-10-11
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
unload me
End Sub
wxrwan 2003-10-09
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
unload me
End Sub
lijinqiang 2003-10-09
  • 打赏
  • 举报
回复
UNLOAD ME
MSSQL 2003-10-09
  • 打赏
  • 举报
回复
说来说去。
也不知道楼主问的是什么了。
不过。如果关闭窗口用unload me就行了
在窗口关闭时会触发sub form_unload()
在这里面你可以写你要处理的程序代码。
zz124 2003-10-09
  • 打赏
  • 举报
回复
在关闭窗口的时候就会自动调用Form_Unload事件,
或者
Private Sub Command1_Click()
unload me
End Sub
cloudtarget 2003-10-09
  • 打赏
  • 举报
回复
不明白楼主的意思
把Form_Unload 中做的事情做成一个过程或函数,在Form_Unload 中可以调用,在按钮事件中也可以调用
qiqunet 2003-10-09
  • 打赏
  • 举报
回复
可能楼主中不过是想调用一下Form_Unload()这个子程序,而不是想退出,那么就不能用
unload me 或 unload formX
而要用
Form_Unload 0 或 Form_Unload 1 或 call Form_Unload(0)
yunfeng007 2003-10-09
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
unload me
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MsgBox("真的退出吗?", vbQuestion + vbYesNo) = vbYes Then
Cancel = False
Else
Cancel = True
End If
End Sub
Reker熊 2003-10-09
  • 打赏
  • 举报
回复
unload
NotReady 2003-10-09
  • 打赏
  • 举报
回复
unload me
aiur2000 2003-10-09
  • 打赏
  • 举报
回复
unloade me
kmzs 2003-10-09
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Form_Unload 0 '(1)
End Sub

Private Sub Form_Unload(Cancel As Integer)
a=MsgBox "确认退出?",35
if a=6 then End else cancel=1
End Sub
viena 2003-10-09
  • 打赏
  • 举报
回复
Form_Unload(Cancel As Integer)明明是有参数的,Cancel表示是否取消卸载窗体,调用这个sub为什么不加参数?
viena 2003-10-09
  • 打赏
  • 举报
回复
同意楼上。要么用unload me,要么另加一函数,分别在Form_Unload中和Command1_Click中调用,否容易造成混乱
lwm1977 2003-10-09
  • 打赏
  • 举报
回复
建议另加一函数
射天狼 2003-10-09
  • 打赏
  • 举报
回复
同意strongfisher(Haiwolf) ,卸载窗口自动就调用此过程了~~
strongfisher 2003-10-09
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
unload me
End Sub


Private Sub Command1_Click()
unload form1
End Sub
northwolves 2003-10-09
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Form_Unload 0 '(1)
End Sub

Private Sub Form_Unload(Cancel As Integer)
MsgBox "确认退出?": End
End Sub
加载更多回复(2)
Dim filem As String '保存文件名 Dim str As String Dim msg Dim bu As Boolean '用于判断文本框中的内容是否改变 Public Nexts As Double '用于存储查找末字符的位置 Public Sv, mo As Double 'sv用于存储查的下一个字符的位置,mo用于存储查找第一次查找字符的位置 Dim Cmt(3) As Single, Cml(3) As Single, Cmw(3) As Single, Cmh(3) As Single Dim Tt(1) As Single, Tl(1) As Single, Tw(1) As Single, Th(1) As Single Dim cht As Single, chl As Single, chw As Single, chh As Single Private Sub Check1_Click() If Check1.Value = 1 Then Label1.Caption = "要连接的末字符" Else Label1.Caption = "要查找的首字符" End If End Sub Private Sub Command1_Click() Dim Ts As String Dim a As Long a = 1048576 cmo1.Filter = "*.txt" cmo1.ShowOpen filem = cmo1.FileName If cmo1.FileName = "" Then Exit Sub End If Ts = Right(cmo1.FileName, 4) If Ts ".txt" Then MsgBox "您打开的非文本文档文件", , "提示" Exit Sub End If If FileLen(filem) \ a > 10 Then MsgBox "您打开的文件已超过10M", , "提示" Exit Sub End If RichTextBox1.FileName = cmo1.FileName bu = False Label3.Caption = "你打开的文件名为:" & filem If FileLen(filem) \ 1024 = 1 And FileLen(filem) / 1024 0 Then '文件有1M时 Label4.Caption = "文件大小为:" & Left(FileLen(filem) / a, 4) & "M" End If Exit Sub End Sub Private Sub Command2_Click() If Label1.Caption = "要查找的首字符" Then If Text1.Text = "" Then MsgBox "请输入要查找的内容" Exit Sub End If Timer3.Enabled = True Command1.Enabled = False Command2.Enabled = False '防止在程序忙时,用户点击其它按扭,导致程序崩溃。 Command3.Enabled = False Label2.Visible = True mo = InStr(RichTextBox1.Text, Text1.Text) Command1.Enabled = True Command2.Enabled = True Command3.Enabled = True Timer3.Enabled = False Label2.Visible = False Sv = mo RichTextBox1.SetFocus DoEvents RichTextBox1.SelStart = mo - 1 RichTextBox1.SelLength = Len(Text1.Text) Label1.Caption = "要查找的末字符" Text1.Text = "" '查找首字符 ElseIf Label1.Caption = "要查找的末字符" Then If Text1.Text = "" Then MsgBox "请输入要查找的内容" Exit Sub End If Timer3.Enabled = True Command1.Enabled = False Command2.Enabled = False Command3.Enabled = False Label2.Visible = True Nexts = InStr(Sv + Len(Text1.Text), RichTextBox1.Text, Text1.Text) 'sv后面加上文本长度是为了从字符后面位置开始查找,否则只会从已查找到字符位置前查找。这样会重复 Command1.Enabled = True Command2.Enabled = True Command3.Enabled = True Timer3.Enabled = False Label2.Visible = False If Nexts = 0 Then MsgBox "未查找到内容", , "提示" Exit Sub End If Sv = Nexts RichTextBox1.SetFocus RichTextBox1.SelStart = Nexts - 1 RichTextBox1.SelLength = Len(Text1.Text) Command2.Caption = "查找下一个" Command2.Enabled = False Timer1.Enabled = True '查找末字符,并把选中的代码交给时间控件 ElseIf Label1.Caption = "要连接的末字符" Then Timer3.Enabled = True Command1.Enabled = False Command2.Enabled = False Command3.Enabled = False Label2.Visible = True mo = InStr(Sv + Len(Text1.Text), RichTextBox1.Text, Text1.Text) Command1.Enabled = True Command2.Enabled = True Command3.Enabled = True Timer3.Enabled = False Label2.Visible = False If mo = 0 Then MsgBox "找不到" Exit Sub End If Sv = mo DoEvents RichTextBox1.SetFocus RichTextBox1.SelStart = mo - 1 RichTextBox1.SelLength = Len(Text1.Text) Command2.Caption = " 查找下一个" Command2.Enabled = False Timer2.Enabled = True '选中文本代码交给时间控件2完成 End If End Sub Private Sub Command3_Click() Call save MsgBox "保存成功" End Sub Private Sub Command4_Click() msg = MsgBox("是否删除选中的字符", vbYesNo + 64, "询问") If msg = vbYes Then str = Replace(RichTextBox1.Text, RichTextBox1.SelText, "") RichTextBox1.SelText = str End If End Sub Sub save() Open filem For Output As #1 Print #1, RichTextBox1.Text Close #1 End Sub Private Sub Form_Load() menpaste.Enabled = False Tt(0) = Text1.Top Tl(0) = Text1.Left Tw(0) = Text1.Width Th(0) = Text1.Height Tt(1) = RichTextBox1.Top Tl(1) = RichTextBox1.Left Tw(1) = RichTextBox1.Width Th(1) = RichTextBox1.Height '保存Combo1控件的Top、Left、Width和Height属性 Cmt(0) = Command1.Top Cml(0) = Command1.Left Cmw(0) = Command1.Width Cmh(0) = Command1.Height End Sub Private Sub Form_Unload(Cancel As Integer) If filem "" And bu = True Then msg = MsgBox("是否保存文件", vbYesNo + 64, "询问") If msg = vbYes Then Command1.Enabled = True Command2.Enabled = True Command3.Enabled = True Timer3.Enabled = False Label2.Visible = False Call save Command1.Enabled = True Command2.Enabled = True Command3.Enabled = True Timer3.Enabled = False Label2.Visible = False MsgBox "保存成功" End If End If End Sub Private Sub mencopy_Click() Clipboard.SetText RichTextBox1.SelText menpaste.Enabled = True End Sub Private Sub menexit_Click() End Sub Private Sub menpaste_Click() RichTextBox1.SelText = Clipboard.GetText End Sub Private Sub RichTextBox1_Change() bu = True If bu = True And filem "" Then Command3.Enabled = True End If End Sub Private Sub RichTextBox1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) If Button = vbRightButton Then PopupMenu menfile End If End Sub Private Sub Timer1_Timer() Static a As Integer a = a + 1 If a = 3 Then Command2.Enabled = True Timer1.Enabled = False '到时间后停止时间控件,以防多次运行 a = 0 msg = MsgBox("是否要将首末字符全部选中", vbYesNo + 64, "询问") '选中所查找的下一个字符 If msg = vbYes Then Timer3.Enabled = True Command1.Enabled = False Command2.Enabled = False Command3.Enabled = False Label2.Visible = True RichTextBox1.SetFocus RichTextBox1.SelStart = mo - 1 RichTextBox1.SelLength = Nexts Command1.Enabled = True Command2.Enabled = True Command3.Enabled = True Timer3.Enabled = False Label2.Visible = False Label1.Caption = "要查找的首字符" Command4.Enabled = True Command2.Caption = "开始查找" End If End If End Sub Private Sub Timer2_Timer() Static b As Integer b = b + 1 If b = 3 Then Timer2.Enabled = False Command2.Enabled = True b = 0 msg = MsgBox("是否从第一个文字到些内容位置全选中", vbYesNo + 64, "询问") If msg = vbYes Then Timer3.Enabled = True Command1.Enabled = False Command2.Enabled = False Command3.Enabled = False Label2.Visible = True RichTextBox1.SetFocus RichTextBox1.SelStart = 1 RichTextBox1.SelLength = mo Command1.Enabled = True Command2.Enabled = True Command3.Enabled = True Timer3.Enabled = False Label2.Visible = False Command4.Enabled = True End If End If End Sub Private Sub Timer3_Timer() Static s As Integer s = s + 1 prog1.Value = s If s Mod 2 = 0 Then DoEvents End If End Sub

7,788

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧