[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