这是我的代码,你能看一下吗?
Option Explicit
Dim i As Integer
Dim A() As String
Dim sql As String
Dim rs_deal As New ADODB.Recordset
Dim sql1 As String
Dim B() As String
Dim t1 As Integer
Dim t2 As Integer
Dim rs_fs As New ADODB.Recordset
Dim m As String
Private Sub form_load()
Text2(0).Text = Format(Date, "yyyy-mm-dd")
Winsock1.Protocol = sckTCPProtocol
Winsock1.LocalPort = 3333
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then
Winsock1.Close
Winsock1.Accept requestID
End If
End Sub
Private Sub Winsock1_dataarrival(ByVal bytestotal As Long)
On Error Resume Next
Dim clientdata As Variant
Winsock1.GetData clientdata, vbString
inf = clientdata
End Sub
Private Sub Winsock1_close()
Winsock1.Close
If inf = "" Then
Winsock1.Listen
Else
inf_save
inf_fs
End If
End Sub
Private Sub inf_save()
Adodc1.connectionstring = "provider =microsoft.jet.oledb.4.0;data source=bus.mdb;jet oledb:database password ='123'"
Adodc1.RecordSource = "select * from 运行信息"
Adodc1.Refresh
Adodc1.Recordset.AddNew
Text2(0).Text = Format(Date, "yyyy-mm-dd")
A = Split(inf, "/")
For i = 1 To 8
Text2(i).Text = A(i - 1)
Next i
sql = "select 站牌名 from 站牌信息 where 所属路线 = '" & A(0) & "' and 站牌编号= '" & A(7) & "'"
rs_deal.Open sql, conn, adOpenKeyset, adLockPessimistic
Text2(9).Text = rs_deal.Fields(0)
station = Text2(9).Text
rs_deal.Close
Adodc1.Recordset.Update
For i = 1 To 9
Text2(i).Text = ""
Next i
End Sub
Private Sub inf_fs()
B = Split(inf, "/")
If B(7) < 200 Then
sql1 = "select 站牌编号,IP,端口 from 站牌信息 where 站牌编号>= '" & B(7) & "' and 站牌编号 < '104' and 所属路线 = '" & B(0) & "'order by 站牌编号"
rs_fs.Open sql1, conn, adOpenKeyset, adLockPessimistic
Else
sql1 = "select 站牌编号,IP,端口 from 站牌信息 where 站牌编号>= '" & B(7) & "' and 站牌编号 <='300'
and 所属路线 = '" & B(0) & "'order by 站牌编号"
rs_fs.Open sql1, conn, adOpenKeyset, adLockPessimistic
End If
Do While Not rs_fs.EOF
t1 = rs_fs.Fields(0) - B(7)
t2 = 5 * t1
m = B(0) & "" & t2 & "" & B(5) & "" & station
Winsock2.Protocol = sckTCPProtocol
Winsock2.RemoteHost = rs_fs.Fields(1)
Winsock2.RemotePort = CLng(rs_fs.Fields(2))
Winsock2.Connect
Do While Not Winsock2.State = sckConnected
DoEvents
Loop
Winsock2.SendData m
Winsock2.Close
m = ""
rs_fs.MoveNext
Loop
rs_fs.Close
Winsock1.Listen
End Sub