在WinSock控件的SendProgress事件中有bytesSent和bytesRemaining两个参数,发送时间=当前时间-发送开始时间,可以直接用系统的Timer属性,单位就是秒,而且有0.01秒的精度,足够了。示例如下:窗体中包含一按钮和Winscok控件Option ExplicitPrivate nStartTimer As LongPrivate Sub Command1_Click() nStartTimer = Timer Winsock1.SendData Data() '发送数据 End SubPrivate Sub Winsock1_SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long) Dim nCurrentTimer As Long Dim nSpeed As Long '传输速度
nCurrentTimer = Timer '当前时间 If nCurrentTimer - nStartTimer = 0 Then '防止分母为0 nSpeed = bytessend / (nCurrentTimer - nStartTimer) Else nSpeed = -1 '速度未知 End If End Sub
nStartTimer = Timer
Winsock1.SendData Data() '发送数据
End SubPrivate Sub Winsock1_SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long)
Dim nCurrentTimer As Long
Dim nSpeed As Long '传输速度
nCurrentTimer = Timer '当前时间
If nCurrentTimer - nStartTimer = 0 Then '防止分母为0
nSpeed = bytessend / (nCurrentTimer - nStartTimer)
Else
nSpeed = -1 '速度未知
End If
End Sub