我想使用Visual Basic 6.0将十六进制数据发送到以太网或 LAN 。十六进制数据将如下所示:
AB7745683ACB76B34E5FF5E99EBC5F878A6BC8E9DF9876BCEA89
在表单上,我有一个文本框,用户将在其中输入这些数据。
如何使用 Visual Basic 6.0 将此十六进制数据发送到 LAN 或以太网?
我想使用Visual Basic 6.0将十六进制数据发送到以太网或 LAN 。十六进制数据将如下所示:
AB7745683ACB76B34E5FF5E99EBC5F878A6BC8E9DF9876BCEA89
在表单上,我有一个文本框,用户将在其中输入这些数据。
如何使用 Visual Basic 6.0 将此十六进制数据发送到 LAN 或以太网?
'1 form with:
' 1 textbox control: name=Text1
' 1 winsock control: name=Winsock1
Option Explicit
Private Sub Command1_Click()
SendCmd Text1.Text
End Sub
Private Sub Form_Load()
Text1.Text = "AB7745683ACB76B34E5FF5E99EBC5F878A6BC8E9DF9876BCEA89"
End Sub
Private Sub SendCmd(strHex As String)
Dim strCmd As String
With Winsock1
'make sure we are connected
DoConnect
'convert hex to cmd
strCmd = Hex2Cmd(strHex)
'send cmd
.SendData strCmd
End With 'Winsock1
End Sub
Private Sub DoConnect()
With Winsock1
If .State <> sckConnected Then
.Connect "192.168.98.17", 5001 'Destination IP address and port
Do Until .State = sckConnected
DoEvents
Loop
End If
End With 'Winsock1
End Sub
Private Function Hex2Cmd(strHex As String) As String
Dim intHex As Integer
Dim strCmd As String
strCmd = ""
For intHex = 1 To Len(strHex) Step 2
strCmd = strCmd & Chr$(Val("&H" & Mid$(strHex, intHex, 2)))
Next intHex
Hex2Cmd = strCmd
End Function