VB循环的问题
Private Sub SendCmd_Click()
Dim cc As New MSSOAPLib30.SoapClient30
Dim xmlString As String
Dim X As MSXML2.DOMDocument40
Dim Temp As String
On Error GoTo NN
Set Cnn1 = New ADODB.Connection
Cnn1.ConnectionString = "DSN = ZCZ; UID =; PWD =;"
Cnn1.Open "DSN=ZCZ"
Set AdoCard = New ADODB.Recordset
AdoCard.CursorType = adOpenKeyset
AdoCard.LockType = adLockOptimistic
AdoCard.Open "SELECT * FROM 市局信息 where 批次='" & Text5.Text & "' and 单据编号 = val ('" & Text14.Text & "') ", Cnn1, adOpenDynamic, adLockOptimistic
Temp = AdoCard!单据编号
A = AdoCard!epc编码
B = AdoCard!车牌号码
C = Text4.Text
D = Text7.Text
E = AdoCard!净重
F = Text8.Text
G = AdoCard!煤票号
H = AdoCard!运往地编码
j = AdoCard!煤炭种类
K = AdoCard!煤类
N = AdoCard!车辆相关信息
i = AdoCard!运往地详细地址
L = AdoCard!入矿时间
M = AdoCard!出矿时间
Set X = New MSXML2.DOMDocument40
X.LoadXml xmlString
cc.MSSoapInit "http://10.90.60.34:8080/yunxiao_service/services/Triman_marketing_Service?wsdl"
xmlString = "<?xml version=""1.0"" encoding=""utf-8""?><DataBody><DataCollect><epcbm>" & A & "</epcbm><cph>" & B & "</cph><mkbh>017200014</mkbh><mkmc>李家塔煤矿</mkmc><pz>" & C & "</pz><rksj>" & L & "</rksj><MoreInfo>" & N & "</MoreInfo><mz>" & D & "</mz><jz>" & E & "</jz><dj>" & F & "</dj><mph>" & G & "</mph><ywdbm>" & H & "</ywdbm><ywdxxdz>" & i & "</ywdxxdz><mtzl>" & j & "</mtzl><ml>" & K & "</ml><cksj>" & M & "</cksj></DataCollect></DataBody>"
X.LoadXml (xmlString)
Text16.Text = xmlString
Text15.Text = cc.readOnceColliery(xmlString)
If Text15.Text = "<?xml version=""1.0"" encoding=""utf-8""?><DataReturn><ReturnCode>1</ReturnCode><ReturnDescription>插入成功</ReturnDescription></DataReturn>" Then
AdoCard!发送状态 = "已发送"
AdoCard.Update
End If
NN:
If Temp = "" Or Err.Number = 3021 Then
MsgBox "您所选择的单据编号没有数据存在,请查询后再发送!", 48, "提示信息"
End If
AdoCard.Close
Cnn1.Close
End Sub
请问:这个程序如何加循环 循环目的是 发送不成功自动重新发送 5次发送失败就弹出“请检查网络环境”
[解决办法]
Dim n as integerdim e as integerPrivate Sub SendCmd_Click()...End If e=0 exit subNN: If Temp = "" Or Err.Number = 3021 Then MsgBox "您所选择的单据编号没有数据存在,请查询后再发送!", 48, "提示信息" End If AdoCard.Close Cnn1.Close e=1End Subprivate sub try5() '发送不成功自动重新发送 5次发送失败就弹出“请检查网络环境”n=0do SendCmd_Click() if e=1 then n=n+1 if n>5 then msgbox "请检查网络环境" exit do endif else exit do endifloopend sub
[解决办法]
将循环控制变量设置为全局变量。再在循环内部调用递加或者减,循环内部写个IF判断全局变量大于几或者小于几,强制跳出循环并将循环控制变量重置
[解决办法]
try5里面调用了SendCmd_Click
当然不能在SendCmd_Click里面调用try5了!