作者clv (给真相=封锁)
看板Visual_Basic
标题[VB6 ] 连续按按键呼叫程式的问题
时间Sat May 30 19:54:13 2015
使用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
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 180.177.156.249
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Visual_Basic/M.1432986856.A.F32.html
1F:推 Yaiba: 程式里没有按钮 06/02 10:48