[VB6 ] 连续按按键呼叫程式的问题

楼主: clv (慢慢習慣成為大叔)   2015-05-30 19:54:13
使用WINSOCK
我点按钮时会去呼叫 sending程式 待server回复或Timeout时 将结果传回
我是希望在执行第一次时如果还没有接收到SOCK的回复时 不要送出第二次
但不知为什么 点两次按钮(中间隔五秒) 他还是直接送给SOCK Server而不是
等第一次结束后才接着送出去 而且sending的结果是错误的
我想程式一定有问题 只是找不到 〉:〈
程式如下
Private ackMsg As String
Private Sub CWINSockTimer_Timer()
CWinsock.Close
B_Sending = False
CWINSockTimer.Enabled = False
ackMsg = "[Err]:TimeOut~"
End Sub
Private Sub Form_Load()
B_Sending = False
CWINSockTimer.Enabled = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
CWinsock.Close
End Sub
Private Sub CWinsock_Connect()
If CWinsock.State = sckConnected Then
CWinsock.SendData sendStr
Else
ackMsg = CWinsock.State
End If
End Sub
Public Function sending(ByVal sockHost As String, ByVal sockPort As Integer,
ByVal tempStr As String, ByVal t_time As Integer) As String
On Error GoTo Oops
Dim RegTime As Variant
RegTime = Now
Do Until B_Sending = False
Sleep 1
DoEvents
If DateDiff("s", Now, RegTime) > t_time Then
sending = "[Err]:TimeOut"
Exit Function
End If
Loop
If B_Sending = False Then
B_Sending = True
CWINSockTimer.Enabled = True
CWINSockTimer.Interval = CLng(t_time) * 1000
sendStr = tempStr
CWinsock.RemoteHost = sockHost
CWinsock.RemotePort = sockPort
CWinsock.Close
ackMsg = ""
CWinsock.Connect
Do Until ackMsg <> ""
Sleep 1
DoEvents
If DateDiff("s", Now, RegTime) > t_time Then ackMsg =
"[Err]:TimeOut"
Loop
sending = ackMsg
CWinsock.Close
CWINSockTimer.Enabled = False
B_Sending = False
End If
Exit Function
Oops:
sending = "[Err]:" & Err.Description
CWinsock.Close
CWINSockTimer.Enabled = False
B_Sending = False
End Function
Private Sub CWinsock_DataArrival(ByVal bytesTotal As Long)
On Error GoTo Oops
Dim temp As String
temp = String(bytesTotal, Chr$(0))
CWinsock.GetData temp, vbString, bytesTotal
ackMsg = temp
Exit Sub
Oops:
ackMsg = "[Err]:" & Err.Description
CWinsock.Close
CWINSockTimer.Enabled = False
B_Sending = False
End Sub
Private Sub CWinsock_Error(ByVal Number As Integer, Description As String,
ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal
HelpContext As Long, CancelDisplay As Boolean)
ackMsg = "[Err]:" & Description & "Code:" & CStr(Number)
CWinsock.Close
CWINSockTimer.Enabled = False
B_Sending = False
End Sub
作者: Yaiba (绯心刀刃)   2015-06-02 10:48:00
程式里没有按钮

Links booklink

Contact Us: admin [ a t ] ucptt.com