社区
VB基础类
帖子详情
Exit sub和End sub有何区别
glmemail
2003-11-02 04:56:51
如题
...全文
473
9
打赏
收藏
Exit sub和End sub有何区别
如题
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
9 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
glmemail
2003-11-02
打赏
举报
回复
谢谢各位
Mclaren
2003-11-02
打赏
举报
回复
再跟一贴,凑凑分
END SUB就好比大门,
EXIT SUB就好比窗户
从门和窗户都可以出去的
一般走门
但情急之下走窗户也行
vbanddelphi
2003-11-02
打赏
举报
回复
呵呵,以上各位都说都恨详细啦!我都没话可说了,我来做个总结吧?
END SUB就好比家里面的大门,
EXIT SUB就好比家里面房间的门!
CCL
2003-11-02
打赏
举报
回复
End sub 是结构语句,可以说是“非运行”的
Exit Sub 则相反
benxie
2003-11-02
打赏
举报
回复
一个SUB只能有一个END SUB,而可以有多个EXIT SUB
yesss
taosihai1only
2003-11-02
打赏
举报
回复
一个SUB只能有一个END SUB,而可以有多个EXIT SUB。
huntgirl
2003-11-02
打赏
举报
回复
从另一方面来说,Exit Sub 是人为设定让程序跳出,不再执行该过程.
而 End sub是此过程自然结束.
例:
sub test()
for i=1 to 10
if i=5 then
exitsub '在指定的条件满足时,退出程序.
end if
next
end sub
busisoft
2003-11-02
打赏
举报
回复
Exit Sub 语句使执行立即从一个 Sub 过程中退出。程序接着从调用该 Sub 过程的语句下一条语句执行。在 Sub 过程的任何位置都可以有 Exit Sub 语句。
End Sub 用于结束一个 Sub 语句。 End 语句提供了一种强迫中止程序的方法
crystal_heart
2003-11-02
打赏
举报
回复
一个SUB只能有一个END SUB,而可以有多个EXIT SUB。
access登录界面
Private
Sub
cmdClose_Click() On Error GoTo Err_cmdClose_Click If MsgBox("是否确定退出系统?", vbQuestion + vbYesNo, "系统提示") = vbYes Then DoCmd.Quit Else
Exit
Sub
End
If
Exit
_cmdClose_Click:
Exit
Sub
Err_cmdClose_Click: MsgBox Err.Description Resume
Exit
_cmdClose_Click
End
Sub
Private
Sub
cmdOK_Click() On Error GoTo Err_cmdOK_Click '第一步 判断用户情况 Call cobUser_LostFocus If blnAsUser = True Then Me.cobUser.SetFocus
Exit
Sub
Else Me.txtPwd.SetFocus
End
If '第二步 判断密码情况 Call txtPwd_LostFocus If blnAsPwd = True Then Me.txtPwd.SetFocus
Exit
Sub
Else Me.lblPwd.ForeColor = RGB(0, 100, 0) Me.lblPwd.Caption = "√" 'MsgBox "测试通过 用户ID =" & userID MsgBox "测试通过!" Me.Visible = False
End
If
Exit
_cmdOK_Click:
Exit
Sub
Err_cmdOK_Click: MsgBox Err.Description Resume
Exit
_cmdOK_Click
End
Sub
Private
Sub
cobUser_LostFocus() On Error GoTo Err_cobUser_LostFocus blnAsUser = False Dim blnUser As Boolean blnUser = False If IsNull(Me.cobUser) Then Me.lblUser.ForeColor = RGB(255, 0, 0) Me.lblUser.Caption = "× 用户名不能为空" blnAsUser = True '当此处不退出,则会运行到 用户不存在的错误提示
Exit
Sub
End
If Set rsAs = New ADODB.Recordset strAsSQL = "SELECT tb_user.用户ID,tb_user.用户名 FROM tb_user" rsAs.Open strAsSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic rsAs.MoveFirst For iAs = 1 To rsAs.RecordCount If rsAs!用户名 = Me!cobUser Then blnUser = True iAs = rsAs.RecordCount + 1 '赋值给全局变量,适用于模块 Macro_modUsersLog Else rsAs.MoveNext
End
If Next iAs rsAs.Close Set rsAs = Nothing If blnUser = False Then Me.lblUser.ForeColor = RGB(255, 0, 0) Me.lblUser.Caption = "× 用户不存在" blnAsUser = True
Exit
Sub
Else Me.lblUser.ForeColor = RGB(0, 100, 0) Me.lblUser.Caption = "√"
End
If
Exit
_cobUser_LostFocus:
Exit
Sub
Err_cobUser_LostFocus: MsgBox Err.Description Resume
Exit
_cobUser_LostFocus
End
Sub
Private
Sub
txtPwd_LostFocus() On Error GoTo Err_txtPwd_LostFocus blnAsPwd = False If IsNull(Me.cobUser) Then Me.lblPwd.Caption = "" Me.cobUser.SetFocus
Exit
Sub
End
If If IsNull(Me.txtPwd) Then Me.lblPwd.ForeColor = RGB(255, 0, 0) Me.lblPwd.Caption = "× 密码不能为空" blnAsPwd = True
End
If If DLookup("密码", "tb_user", "[用户名]=" & "'" & Me!cobUser & "'") <> Me!txtPwd Then Me.lblPwd.ForeColor = RGB(255, 0, 0) Me.lblPwd.Caption = "× 密码错误" blnAsPwd = True
End
If
Exit
_txtPwd_LostFocus:
Exit
Sub
Err_txtPwd_LostFocus: MsgBox Err.Description Resume
Exit
_txtPwd_LostFocus
End
Sub
VB+SQL教学管理系统
VB+SQL教学管理系统哦rivate
Sub
cmdok_Click() Dim txtsql As String Dim mrc As ADODB.Recordset Dim msgtext As String If Trim(txtusername.Text) = "" Then MsgBox "请输入用户名称!", vbOKOnly, "警告"
Exit
Sub
End
If '判断输入的密码是否一致 If Trim(txtpassword1.Text) <> Trim(txtpassword2.Text) Then MsgBox "两次输入密码不一样,请确认!", vbOKOnly, "警告"
Exit
Sub
End
If If Len(txtpassword1.Text) = 0 Then MsgBox "输入密码不能为空!", vbOKOnly, "警告"
Exit
Sub
End
If txtsql = "select*from user_info where user_ID ='" & txtusername.Text & "'" Set mrc = executesql(txtsql, msgtext) If mrc.EOF Then mrc.addnew mrc.fields("user_ID") = Trim(txtusername.Text) mrc.Update MsgBox "添加用户成功!", vbOKOnly, "添加用户" Else MsgBox "用户已经存在,请重新输入用户名!", vbOKOnly, "警告"
Exit
Sub
End
If Private
Sub
cmbcancel_click() Unload Me
End
Sub
简单贪吃蛇游戏-vb 2008
简单的贪吃蛇游戏,由vb2008编的 部分代码如下: Private
Sub
Form_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer) Dim C As Long If KeyCode = 27 Then
End
If KeyCode = 32 Then If Timer1.Enabled = True Then Timer1.Enabled = False Label1.Visible = True Else Timer1.Enabled = True Label1.Visible = False
End
If
End
If C = UBound(She) If GFangXiang = True Then
Exit
Sub
Select Case KeyCode Case 37 If She(C).F = 2 Then
Exit
Sub
She(C).F = 0 GFangXiang = True Case 38 If She(C).F = 3 Then
Exit
Sub
She(C).F = 1 GFangXiang = True Case 39 If She(C).F = 0 Then
Exit
Sub
She(C).F = 2 GFangXiang = True Case 40 If She(C).F = 1 Then
Exit
Sub
She(C).F = 3 GFangXiang = True
End
Select
End
Sub
手机管理系统
操作简单,适合小型手机店铺。Dim rs1 As New ADODB.Recordset Private
Sub
cmd
exit
_Click() frmmain.Visible = True Unload Me
End
Sub
Private
Sub
cmdOK_Click() If txtuserid.Text = "" Then MsgBox "请输入操作员编号!", vbOKOnly + vbInformation, "修改密码" txtuserid.Text = "" txtuserid.SetFocus
Exit
Sub
Else rs1.Open "select * from 密码 where 操作员编号= '" & Trim(txtuserid.Text) & "'", cnn, adOpenKeyset, adLockOptimistic If rs1.RecordCount > 0 Then txtusername.Text = Trim(rs1.Fields("操作员名称"))
End
If rs1.Close
End
If If txtusername.Text = "" Then MsgBox "操作员编号不存在!", vbOKOnly + vbInformation, "修改密码" txtuserid.Text = "" txtuserid.SetFocus
Exit
Sub
End
If If txtoldpass.Text = "" Then MsgBox "请输入旧密码!", vbOKOnly + vbInformation, "修改密码" txtoldpass.SetFocus
Exit
Sub
End
If If txtnewpass.Text = "" Then MsgBox "请输入新密码!", vbOKOnly + vbInformation, "修改密码" txtnewpass.SetFocus
Exit
Sub
End
If If txtnewpass1.Text = "" Then MsgBox "请再次输入新密码!", vbOKOnly + vbInformation, "修改密码" txtnewpass1.SetFocus
Exit
Sub
End
If rs1.Open "select * from 密码 where 操作员编号= '" & Trim(txtuserid.Text) & "'", cnn, adOpenKeyset, adLockOptimistic If rs1.RecordCount > 0 Then If txtoldpass.Text <> Trim(rs1.Fields("密码")) Then MsgBox "旧密码不正确!", vbOKOnly + vbInformation, "修改密码" txtoldpass.Text = "" txtoldpass.SetFocus Else If txtnewpass.Text = txtnewpass1.Text Then rs1.Fields("密码") = txtnewpass.Text rs1.Update MsgBox "密码修改成功!", vbOKOnly + vbInformation, "修改密码" rs1.Update txtuserid.SetFocus Else MsgBox "两次输入的密码不一致,请重新输入!", vbOKOnly + vbInformation, "修改密码" txtnewpass.Text = "" txtnewpass1.Text = "" txtnewpass.SetFocus
End
If
End
If
End
If rs1.Close
End
Sub
Private
Sub
Form_Activate() txtuserid.SetFocus
End
Sub
Private
Sub
txtNewPass_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then txtnewpass1.SetFocus
End
If
End
Sub
Private
Sub
txtNewPass1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then cmdok.SetFocus
End
If
End
Sub
Private
Sub
txtOldPass_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then txtnewpass.SetFocus
End
If
End
Sub
Private
Sub
txtUserId_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then txtoldpass.SetFocus
End
If
End
Sub
Private
Sub
txtUserId_Change() txtusername.Text = "" txtoldpass.Text = "" txtnewpass.Text = "" txtnewpass1.Text = ""
End
Sub
Private
Sub
txtuserid_LostFocus() rs1.Open "select * from 密码 where 操作员编号= '" & Trim(txtuserid.Text) & "'", cnn, adOpenKeyset, adLockOptimistic If rs1.RecordCount > 0 Then If rs1.RecordCount > 0 Then txtusername.Text = Trim(rs1.Fields("操作员名称")) If txtusername.Text = "" Then MsgBox "操作员编号不存在!", vbOKOnly + vbInformation, "修改密码" txtuserid.Text = "" txtuserid.SetFocus
Exit
Sub
End
If
End
If
End
If rs1.Close
End
Sub
简单万年历
采用vb im d As Integer Dim vHour%, vState$ Dim Tim As String, b As Long, H As Integer, M As Integer, S As Long Private
Sub
Command1_Click() S = fun(Month(Now), Year(Now))
End
Sub
Private
Sub
Command2_Click()
End
End
Sub
Private
Sub
Command3_Click() If Val(Text1.Text) > 11 Then Text1.Text = 0 Text2.Text = Val(Text2.Text) + 1
End
If Text1.Text = Val(Text1.Text) + 1 S = fun(Val(Text1.Text), Val(Text2.Text))
End
Sub
Private
Sub
Command4_Click() If Val(Text1.Text) < 2 Then Text1.Text = 13 Text2.Text = Val(Text2.Text) - 1
End
If Text1.Text = Val(Text1.Text) - 1 S = fun(Val(Text1.Text), Val(Text2.Text))
End
Sub
Private
Sub
Command5_Click() If Val(Text2.Text) < 0 Then MsgBox "不能为负年", 64, "通知"
End
If Text2.Text = Val(Text2.Text) + 1 Text1.Text = Val(Text1.Text) S = fun(Val(Text1.Text), Val(Text2.Text))
End
Sub
Private
Sub
Command6_Click() Text2.Text = Val(Text2.Text) - 1 Text1.Text = Val(Text1.Text) S = fun(Val(Text1.Text), Val(Text2.Text))
End
Sub
Private
Sub
Form_Load() Tim = Time Timer1.Interval = 100 Text2.Text = Year(Now) Text1.Text = Month(Now)
End
Sub
Private
Sub
Picture1_Click() MsgBox "美女漂亮吧", 64, "美女"
End
Sub
Private
Sub
Text1_DblClick() If Val(Text1.Text) > 12 Or Val(Text1.Text) < 1 Then MsgBox "月份不在范围内", 64, "提示"
Exit
Sub
End
If
End
Sub
Private
Sub
Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then KeyAscii = 0 If Text1.Text > 0 And Text1.Text < 13 Then S = fun(Text1.Text, Text2.Text) Else 日历.Cls MsgBox "月份不在范围内", 64, "提示"
Exit
Sub
End
If
End
Sub
Private
Sub
Text2_DblClick() If Val(Text2.Text) < 1 Then MsgBox "年份份不在范围内", 64, "提示"
Exit
Sub
End
If S = fun(Text1.Text, Text2.Text)
End
Sub
Private
Sub
Text2_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then KeyAscii = 0 If Text2.Text > 0 Then S = fun(Text1.Text, Text2.Text) Else 日历.Cls MsgBox "月份不在范围内", 64, "提示"
Exit
Sub
End
If
End
Sub
VB基础类
7,771
社区成员
197,588
社区内容
发帖
与我相关
我的任务
VB基础类
VB 基础类
复制链接
扫一扫
分享
社区描述
VB 基础类
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章