小弟就这些分,为了解决这个问题,分数都 奉献除了
'开始窗体相应事件过程
Private Sub form****
on error goto ERRDel'设置错误捕获,放在第一行
……'其它需要的代码
'调用子过程
Call ShipSailAccount_guozhang1101
Call ShipSailAccount_guozhang1102
Call ShipSailAccount_guozhang1103
Call ShipSailAccount_guozhang1104
''日志表
ssql = "insert into 过帐状态表(过帐时间,开船时间,状态) values ('" & DtToday & "','" & DepartDate & "','1') "
cn.Execute ssql, rdExecDirect
Exit Sub '//错误处理
ERRDel:
ssql = "insert into 过帐状态表(过帐时间,开船时间,状态) values ('" & DtToday & "','" & DepartDate & "','0') "
cn.Execute ssql, rdExecDirect
MsgBox "本次自动过帐不成功,请选择手动过帐!"
Form3.Show 1
End sub'结束窗体事件
我如以上加上错误处理我想实现:如果四个方法1101,1102,1103,1104都成功!执行:''日志表
ssql = "insert into 过帐状态表(过帐时间,开船时间,状态) values ('" & DtToday & "','" & DepartDate & "','1') "
cn.Execute ssql, rdExecDirect
若4个方法中有任一个错误,都要执行:ssql = "insert into 过帐状态表(过帐时间,开船时间,状态) values ('" & DtToday & "','" & DepartDate & "','0') "
cn.Execute ssql, rdExecDirect
MsgBox "本次自动过帐不成功,请选择手动过帐!"
Form3.Show 1
并跳出。
如上所想,是在窗体事件里进行错误处理,还是分别在方法中进行错误处理,如何处理呢?
我放在窗体如我上面所处理,我把方法中故意弄了个错,可是无法进行处理,这是什么问题呢?
万分感激!!若有所不明白。请看:http://topic.csdn.net/u/20090416/09/0429a5ae-e210-4db3-a6cb-0cfe19e6988b.html
http://topic.csdn.net/u/20090410/15/df1753c2-7e3d-40b7-85cb-020ff7aee296.html
是我上周的提问,但问题还未解决!
'开始窗体相应事件过程
Private Sub form****
on error goto ERRDel'设置错误捕获,放在第一行
……'其它需要的代码
'调用子过程
Call ShipSailAccount_guozhang1101
Call ShipSailAccount_guozhang1102
Call ShipSailAccount_guozhang1103
Call ShipSailAccount_guozhang1104
''日志表
ssql = "insert into 过帐状态表(过帐时间,开船时间,状态) values ('" & DtToday & "','" & DepartDate & "','1') "
cn.Execute ssql, rdExecDirect
Exit Sub '//错误处理
ERRDel:
ssql = "insert into 过帐状态表(过帐时间,开船时间,状态) values ('" & DtToday & "','" & DepartDate & "','0') "
cn.Execute ssql, rdExecDirect
MsgBox "本次自动过帐不成功,请选择手动过帐!"
Form3.Show 1
End sub'结束窗体事件
我如以上加上错误处理我想实现:如果四个方法1101,1102,1103,1104都成功!执行:''日志表
ssql = "insert into 过帐状态表(过帐时间,开船时间,状态) values ('" & DtToday & "','" & DepartDate & "','1') "
cn.Execute ssql, rdExecDirect
若4个方法中有任一个错误,都要执行:ssql = "insert into 过帐状态表(过帐时间,开船时间,状态) values ('" & DtToday & "','" & DepartDate & "','0') "
cn.Execute ssql, rdExecDirect
MsgBox "本次自动过帐不成功,请选择手动过帐!"
Form3.Show 1
并跳出。
如上所想,是在窗体事件里进行错误处理,还是分别在方法中进行错误处理,如何处理呢?
我放在窗体如我上面所处理,我把方法中故意弄了个错,可是无法进行处理,这是什么问题呢?
万分感激!!若有所不明白。请看:http://topic.csdn.net/u/20090416/09/0429a5ae-e210-4db3-a6cb-0cfe19e6988b.html
http://topic.csdn.net/u/20090410/15/df1753c2-7e3d-40b7-85cb-020ff7aee296.html
是我上周的提问,但问题还未解决!
解决方案 »
- 急,事件处理问题
- 新手求助,怎样获得本机的IP 地址!!!
- 麻烦大家帮帮忙,请问如何使用vb实现ftp服务器中文件的下载?
- SQL
- ado版本覆盖会产生何不良结果?
- 再问一个使用api函数关闭屏保的代码
- vb中如何实现vc中sleep的功能
- 一個關於腳本的問題,還請高手不吝出招!!(進者有分)
- 关于autocad中的菜单定制
- ************哪位大侠作过能自动根据所选字段生成SELECT语句的程序?小弟正想做一个这样的程序,以后写再复杂的SQL也不怕了!!但不知从何下手!***************************
- mshflexgrid中,如何将最后两列的最后四行左右合并
- 关于MSFlexGrid1右键菜单的复制问题
private function shipSailAccount_guozhang1101() as boolean
on error goto errhandle
shipsailaccount_guozhang1101=true '默认为true
....
....
exit function
'如果出错,则返回false
errhandle:
shipsailaccount_guozhang1101=false
exit fucntion
end function'执行例子:
Private Sub form_load()
dim blnIsFalse as boolean
on error goto ERRDel'设置错误捕获,放在第一行
……'其它需要的代码
'调用子过程
blnisfalse=true '默认为执行成功
if ShipSailAccount_guozhang1101()=false then blnisfalse=false
if ShipSailAccount_guozhang1102()=false then blnisfalse=false
if ShipSailAccount_guozhang1103()=false then blnisfalse=false
if ShipSailAccount_guozhang1104()=false then blnisfalse=false
if blnisfalse=false then
ssql = "insert into 过帐状态表(过帐时间,开船时间,状态) values ('" & DtToday & "','" & DepartDate & "','1') "
cn.Execute ssql, rdExecDirect
else
ssql = "insert into 过帐状态表(过帐时间,开船时间,状态) values ('" & DtToday & "','" & DepartDate & "','0') "
cn.Execute ssql, rdExecDirect
MsgBox "本次自动过帐不成功,请选择手动过帐!"
Form3.Show 1
end if
Exit Sub
ERRDel:
End sub'结束窗体事件
blnisfalse=true '默认为执行成功
if ShipSailAccount_guozhang1101()=false then blnisfalse=false '这里如果有一个不成功,就没有必要再去自行后面的三句语句了,加else判断就好了
if ShipSailAccount_guozhang1102()=false then blnisfalse=false
if ShipSailAccount_guozhang1103()=false then blnisfalse=false
if ShipSailAccount_guozhang1104()=false then blnisfalse=false
楼主的方法,如果ERRDel下的cn.execute方法失败,就是死循环了...
楼主的方法,如果ERRDel下的cn.execute方法失败,不是死循环,这个地方错误处理程序已经捕捉到了前面出现的错误,如果此地cn.execute方法失败,应该是直接挂了...
'DepartDate = Format(DTPDate_gz, "yyyy-mm-dd")
DepartDate = Format(Now - 1, "yyyy-mm-dd") isAdd = 1
sql = "select distinct Regularno,Shipno,AccountNo from shipsailaccount where convert(varchar(10),departdate,120)='" & DepartDate & "'"
Set rst = cn.OpenResultset(sql, rdOpenStatic, rdConcurReadOnly, rdAsyncEnable Or rdExecDirect)
While rst.StillExecuting: DoEvents: Wend
If Not rst.EOF Then
rst.MoveFirst
For i = 1 To rst.RowCount
ShipNo = Trim(rst!ShipNo)
RegularNo = Trim(rst!RegularNo)
AccountNo = Trim(rst!AccountNo)
quanprice = 0
banprice = 0
lingprice = 0
quanprice1 = 0
banprice1 = 0
..............................
'
sql_KC = "select SeatTypeNo,price,price1,price3,price4,price-price1-price3-price4 as jiagtj From recordtable " _
& "where convert(varchar(10),recordtable.departdate,120)='" & DepartDate & "' and recordtable.shipno='" & ShipNo & "' and recordtable.regularno='" & RegularNo & "' " _
& "and (recordtable.serialno=0 or recordtable.serialno in (select .lsxh from " _
& "where convert(varchar(10),.departdate,120)='" & DepartDate & "' and .k14='" & ShipNo & "' and .regularno='" & RegularNo & "' " _
& "and .isaccount=1 and .TPQK=0 and .loadtype='10')) and recordtable.rtstate=0 and recordtable.loadtype='10'" _
& " union all select SeatTypeNo,price,price1,price3,price4,price-price1-price3-price4 as jiagtj From recordbackup " _
& "where convert(varchar(10),recordbackup .departdate,120)='" & DepartDate & "' and recordbackup .shipno='" & ShipNo & "' and recordbackup .regularno='" & RegularNo & "' " _
& "and (recordbackup .serialno=0 or recordbackup .serialno in (select backup.lsxh from backup " _
& "where convert(varchar(10),backup.departdate,120)='" & DepartDate & "' and backup.k14='" & ShipNo & "' and backup.regularno='" & RegularNo & "' " _
& "and backup.isaccount=1 and backup.TPQK=0 and backup.loadtype='10')) and recordbackup.rtstate=0 and recordbackup.loadtype='10'"
Set rst_KC = cn.OpenResultset(sql_KC, rdOpenStatic, rdConcurReadOnly, rdAsyncEnable Or rdExecDirect)
While rst.StillExecuting: DoEvents: Wend
If Not rst_KC.EOF Then
rst_KC.MoveFirst
For j = 1 To rst_KC.RowCount
If rst_KC!SeatTypeNo = "1" Then
quanprice = quanprice + Round(IIf(IsNull(rst_KC!Price), 0, Trim(rst_KC!Price)), 2)
quanprice1 = quanprice1 + Round(IIf(IsNull(rst_KC!Price1), 0, Trim(rst_KC!Price1)), 2)
Price = Round(IIf(IsNull(rst_KC!Price), 0, Trim(rst_KC!Price)), 2)
Price1 = Round(IIf(IsNull(rst_KC!Price1), 0, Trim(rst_KC!Price1)), 2)
quan = quan + 1
End If
If rst_KC!SeatTypeNo = "2" Then
banprice = banprice + Round(IIf(IsNull(rst_KC!Price), 0, Trim(rst_KC!Price)), 2)
banprice1 = banprice1 + Round(IIf(IsNull(rst_KC!Price1), 0, Trim(rst_KC!Price1)), 2)
ban = ban + 1
End If
If rst_KC!SeatTypeNo = "4" Then
lingprice = lingprice + Round(IIf(IsNull(rst_KC!Price), 0, Trim(rst_KC!Price)), 2)
lingprice1 = lingprice1 + Round(IIf(IsNull(rst_KC!Price1), 0, Trim(rst_KC!Price1)), 2)
ling = ling + 1
End If
price_hx = price_hx + Round(IIf(IsNull(rst_KC!Price4), 0, Trim(rst_KC!Price4)), 2)
price_gw = price_gw + Round(IIf(IsNull(rst_KC!Price3), 0, Trim(rst_KC!Price3)), 2)
price_tjjj = price_tjjj + Round(IIf(IsNull(rst_KC!jiagtj), 0, Trim(rst_KC!jiagtj)), 2)
rst_KC.MoveNext
Next
End If
'
sql_KC = "select .total_tran_wei,.k13,.carlength,.carwidth,substring(.cldm,2,1) as carclass,.k06,.HAJB,isnull(.isdrive,1) as isdrive, " _
& "gkfy.GKF01, gkfy.GKF02, gkfy.GKF03, gkfy.GKF08, gkfy.GKF09 " _
& "From Mark left join gkfy on .lsxh=gkfy.lsxh " _
& "where .k14='" & ShipNo & "' and .regularno='" & RegularNo & "' and convert(varchar (10),.departdate,120)='" & DepartDate & "' " _
& "and .isaccount=1 and .TPQK=0 and .loadtype='10'" _
& " union all select Backup.total_tran_wei,Backup.k13,Backup.carlength,Backup.carwidth, isnull (Backup.isdrive,1) as isdrive, " _
& "substring(Backup.cldm,2,1) as carclass,Backup.k06,Backup.HAJB, " _
& "gkfyBackup.GKF01 , gkfyBackup.GKF02, gkfyBackup.GKF03, gkfyBackup.GKF08, gkfyBackup.GKF09 " _
& "From Backup left join gkfyBackup on Backup.lsxh=gkfyBackup.lsxh " _
& "where Backup.k14='" & ShipNo & "' and Backup.regularno='" & RegularNo & "' " _
& "and convert(varchar(10),Backup.departdate,120)='" & DepartDate & "' " _
& "and Backup.isaccount=1 and backup.TPQK=0 and backup.loadtype='10' "
Set rst_KC = cn.OpenResultset(sql_KC, rdOpenStatic, rdConcurReadOnly, rdAsyncEnable Or rdExecDirect)
While rst.StillExecuting: DoEvents: Wend
If Not rst_KC.EOF Then
rst_KC.MoveFirst
For j = 1 To rst_KC.RowCount
If rst_KC!carclass = "1" Then
If Round(IIf(IsNull(rst_KC!carwidth), 0, Trim(rst_KC!carwidth)), 2) > 3.1 And Round(IIf(IsNull(rst_KC! carlength), 0, Trim(rst_KC!carlength)), 2) > 18 Then
cyf1 = cyf1 + Round(IIf(IsNull(rst_KC!GKF01), 0, Trim(rst_KC!GKF01)), 2) * 2.5
GKF02 = GKF02 + Round(IIf(IsNull(rst_KC!GKF02), 0, Trim(rst_KC!GKF02)), 2) * 2.5
GKF03 = GKF03 + Round(IIf(IsNull(rst_KC!GKF03), 0, Trim(rst_KC!GKF03)), 2) * 2.5
GKF08 = GKF08 + Round(IIf(IsNull(rst_KC!GKF08), 0, Trim(rst_KC!GKF08)), 2) * 2.5
GKF09 = GKF09 + Round(IIf(IsNull(rst_KC!GKF09), 0, Trim(rst_KC!GKF09)), 2) * 2.5
Else
If Round(IIf(IsNull(rst_KC!carwidth), 0, Trim(rst_KC!carwidth)), 2) > 3.1 And Round(IIf(IsNull(rst_KC! carlength), 0, Trim(rst_KC!carlength)), 2) <= 18 Then
cyf1 = cyf1 + Round(IIf(IsNull(rst_KC!GKF01), 0, Trim(rst_KC!GKF01)), 2) * 1.5
GKF02 = GKF02 + Round(IIf(IsNull(rst_KC!GKF02), 0, Trim(rst_KC!GKF02)), 2) * 1.5
GKF03 = GKF03 + Round(IIf(IsNull(rst_KC!GKF03), 0, Trim(rst_KC!GKF03)), 2) * 1.5
GKF08 = GKF08 + Round(IIf(IsNull(rst_KC!GKF08), 0, Trim(rst_KC!GKF08)), 2) * 1.5
GKF09 = GKF09 + Round(IIf(IsNull(rst_KC!GKF09), 0, Trim(rst_KC!GKF09)), 2) * 1.5
Else
cyf1 = cyf1 + Round(IIf(IsNull(rst_KC!GKF01), 0, Trim(rst_KC!GKF01)), 2)
GKF02 = GKF02 + Round(IIf(IsNull(rst_KC!GKF02), 0, Trim(rst_KC!GKF02)), 2)
GKF03 = GKF03 + Round(IIf(IsNull(rst_KC!GKF03), 0, Trim(rst_KC!GKF03)), 2)
GKF08 = GKF08 + Round(IIf(IsNull(rst_KC!GKF08), 0, Trim(rst_KC!GKF08)), 2)
GKF09 = GKF09 + Round(IIf(IsNull(rst_KC!GKF09), 0, Trim(rst_KC!GKF09)), 2)
End If
省略部分代码
rst_KC.Update
rst.MoveNext
Next
rst_KC.Close
End If
rst.Close
End Sub 以上为方法1
其他方法雷同
如何改错误处理啊
还是不怎么明白,新手,不好意思咯
on error goto errhandle
ShipSailAccount_guozhang1101=true '默认为成功
'以下为你的代码
'......
'......
'......
exit function '处理结束
'出错,跳至此处
errhandle:
ShipSailAccount_guozhang1101=false '处理失败
exit function
end function
通过判断每一个函数是否执行成功来决定
if ShipSailAccount_guozhang1101()=false then blnisfalse=false
if ShipSailAccount_guozhang1102()=false then blnisfalse=false
if ShipSailAccount_guozhang1103()=false then blnisfalse=false
if ShipSailAccount_guozhang1104()=false then blnisfalse=false
if blnisfalse=false then
ssql = "insert into 过帐状态表(过帐时间,开船时间,状态) values ('" & DtToday & "','" & DepartDate & "','1') "
cn.Execute ssql, rdExecDirect
else
ssql = "insert into 过帐状态表(过帐时间,开船时间,状态) values ('" & DtToday & "','" & DepartDate & "','0') "
cn.Execute ssql, rdExecDirect
MsgBox "本次自动过帐不成功,请选择手动过帐!"
Form3.Show 1
end if
Exit Sub
ERRDel:
End sub'结束窗体事件
加else 总是有错,如楼下所说,如果方法中有错误的,那么下面的方法就不用执行了,以上写法是有错误,也执行下面的方法,请问如何写成有错就不执行其它方法啊?谢谢
应该怎么处理呢?谢谢