?? mtmo.bas
字號:
Attribute VB_Name = "mtmo"
Option Explicit
'獲取命令ID
Public Function GetID(Bins() As Byte) As Long
Dim Flag As Integer
Dim i As Integer
Dim R As Long
Flag = 1
If Bins(0) = &H80 Then Flag = -1
R = 0
For i = 1 To 3
R = R * 256 + Bins(i)
Next
GetID = Flag * R
End Function
'獲取時間
Public Function SetTime() As Double
Dim Ttime As String
Dim Tint As Integer
Dim mydate As Date
Ttime = Month(Date)
Tint = Day(Date)
If Tint < 10 Then Ttime = Ttime & "0"
Ttime = Ttime & Tint
Tint = Hour(Time)
If Tint < 10 Then Ttime = Ttime & "0"
Ttime = Ttime & Tint
Tint = Minute(Time)
If Tint < 10 Then Ttime = Ttime & "0"
Ttime = Ttime & Tint
Tint = Second(Time)
If Tint < 10 Then Ttime = Ttime & "0"
Ttime = Ttime & Tint
SetTime = Ttime
End Function
Public Function FormatTime(dTime As Double) As String
Dim Str As String
Dim Rtn As String
Dim i As Integer
Str = dTime
Rtn = Year(Date)
For i = 1 To 4 Step 2
Rtn = Rtn & "-" & Mid(Str, i, 2)
Next
Rtn = Rtn & " " & Mid(Str, 5, 2)
For i = 7 To 10 Step 2
Rtn = Rtn & ":" & Mid(Str, i, 2)
Next
FormatTime = Rtn
End Function
Public Function inc(ByVal i As Long) As Long '返回i+1
'序號加一
Select Case i
Case &H7FFFFFFF
inc = &H80000000
Exit Function
Case &HFFFFFFFF
inc = 0
Exit Function
Case Else
inc = i + 1
End Select
End Function
Public Sub Send_4byte(ByVal d As Long, sck As Winsock) 'send a long data,htonl
Dim i As Byte
Dim b(3) As Integer
Dim f As Byte 'sign flag
f = 0
If d < 0 Then
f = &H80
d = d And &H7FFFFFFF
End If
For i = 0 To 3
b(i) = d Mod 256
d = d \ 256
Next
sck.SendData CByte(b(3) And 255) Or f
sck.SendData CByte(b(2) And 255)
sck.SendData CByte(b(1) And 255)
sck.SendData CByte(b(0) And 255)
End Sub
Public Function SendHead(Lens As Long, IDs As Long, Nums As Long, sck As Winsock) As Boolean
'lens 包總長度 Nums遞增序號
'總長度
Send_4byte Lens, sck
'命令
Send_4byte IDs, sck
'節(jié)點號
sck.SendData JieDian
'時間
Send_4byte SetTime, sck
'遞增序號
Send_4byte Nums, sck
End Function
Public Function SendHeadResp(Lens As Long, IDs As Long, nos() As Byte, sck As Winsock) As Boolean
'lens 包總長度 Nums遞增序號
'總長度
Send_4byte Lens, sck
'命令
Send_4byte IDs, sck
'原序列號
sck.SendData nos
End Function
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -