Winsock1.RemoteHost = "172.16.66.158" '以后要改为B机的IP地址 Winsock1.RemotePort = 2000 Winsock1.Connect '连接B机 Label4.Caption = "第0次:" + Str(Winsock1.State)End Sub Private Sub Form_Unload(Cancel As Integer) Winsock1.Close End SubPrivate Sub Timer1_Timer() If Second(Time) > 0 Then Exit Sub End If 'Winsock1.RemoteHost = "172.16.66.158" '以后要改为B机的IP地址 'Winsock1.RemotePort = 2000 If Winsock1.State <> 7 Then Label4.Caption = "<>7重连一次:" + Str(Winsock1.State) Winsock1.CloseWinsock1.RemoteHost = "172.16.66.158" '以后要改为B机的IP地址 Winsock1.RemotePort = 2000 Winsock1.Connect End If '连接B机 Label4.Caption = "第一次:" + Str(Winsock1.State)With cmd .ActiveConnection = cn .CommandType = adCmdText .CommandText = "select * from tabsend where 上传='N'" End With
Set rsshow = New ADODB.Recordset With rsshow .CursorLocation = adUseClient .CursorType = adOpenDynamic .LockType = adLockOptimistic .Open cmd If Not (.BOF And .EOF) Then .MoveLast Set dgmeter.DataSource = rsshow a = dgmeter.Columns(0) 'Text1.Text b = dgmeter.Columns(1) 'Text2.Text c = dgmeter.Columns(2) 'Text3.Text d = dgmeter.Columns(3) 'Text4.Text sendstr = a + "*" + b + "%" + c + "$" + d Label2.Caption = sendstr Label3.Caption = "" Label3.Caption = "发之前的状态:" + Str(Winsock1.State) 'Winsock1.Close If Winsock1.State <> 7 Then Label4.Caption = "第二次uqw 连:" + Str(Winsock1.State) Winsock1.CloseWinsock1.RemoteHost = "172.16.66.158" '以后要改为B机的IP地址 Winsock1.RemotePort = 2000 Winsock1.Connect Label6.Caption = "最后连:" + Str(Winsock1.State) End If Label7.Caption = "最后jjjjjjj连:" + Str(Winsock1.State) If Winsock1.State = 7 Then Label5.Caption = "=7现在就发的状态" + Str(Winsock1.State) 'A机对外发送 Winsock1.SendData sendstr rsshow!上传 = "Y" rsshow.Update End If End If End With delayTime = Timer + 1 Do While delayTime > Timer DoEvents Loop rsshow.Close End SubPrivate Sub Winsock1_Close() Winsock1.Close End Sub
Private Sub Form_Load()
'打开数据库
'Text1.Text = ""
'Text2.Text = ""
'Text3.Text = ""
'Text4.Text = ""
Set cn = New ADODB.Connection
strcn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & paths & "meter.mdb;Persist Security Info=false"
cn.ConnectionString = strcn
cn.Open
Winsock1.RemoteHost = "172.16.66.158" '以后要改为B机的IP地址
Winsock1.RemotePort = 2000
Winsock1.Connect '连接B机
Label4.Caption = "第0次:" + Str(Winsock1.State)End Sub
Private Sub Form_Unload(Cancel As Integer)
Winsock1.Close
End SubPrivate Sub Timer1_Timer()
If Second(Time) > 0 Then
Exit Sub
End If
'Winsock1.RemoteHost = "172.16.66.158" '以后要改为B机的IP地址
'Winsock1.RemotePort = 2000
If Winsock1.State <> 7 Then
Label4.Caption = "<>7重连一次:" + Str(Winsock1.State)
Winsock1.CloseWinsock1.RemoteHost = "172.16.66.158" '以后要改为B机的IP地址
Winsock1.RemotePort = 2000
Winsock1.Connect
End If
'连接B机
Label4.Caption = "第一次:" + Str(Winsock1.State)With cmd
.ActiveConnection = cn
.CommandType = adCmdText
.CommandText = "select * from tabsend where 上传='N'"
End With
Set rsshow = New ADODB.Recordset
With rsshow
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open cmd
If Not (.BOF And .EOF) Then
.MoveLast
Set dgmeter.DataSource = rsshow a = dgmeter.Columns(0) 'Text1.Text
b = dgmeter.Columns(1) 'Text2.Text
c = dgmeter.Columns(2) 'Text3.Text
d = dgmeter.Columns(3) 'Text4.Text
sendstr = a + "*" + b + "%" + c + "$" + d
Label2.Caption = sendstr
Label3.Caption = ""
Label3.Caption = "发之前的状态:" + Str(Winsock1.State)
'Winsock1.Close
If Winsock1.State <> 7 Then
Label4.Caption = "第二次uqw 连:" + Str(Winsock1.State)
Winsock1.CloseWinsock1.RemoteHost = "172.16.66.158" '以后要改为B机的IP地址
Winsock1.RemotePort = 2000
Winsock1.Connect
Label6.Caption = "最后连:" + Str(Winsock1.State)
End If
Label7.Caption = "最后jjjjjjj连:" + Str(Winsock1.State)
If Winsock1.State = 7 Then
Label5.Caption = "=7现在就发的状态" + Str(Winsock1.State)
'A机对外发送
Winsock1.SendData sendstr
rsshow!上传 = "Y"
rsshow.Update
End If
End If
End With
delayTime = Timer + 1
Do While delayTime > Timer
DoEvents
Loop
rsshow.Close
End SubPrivate Sub Winsock1_Close()
Winsock1.Close
End Sub