如题所述
VB6.0å¯ä½¿ç¨Hexå½æ°å°Byteåæ°æ®è½¬æ¢ä¸ºåå è¿å¶Stringåæ°æ®ï¼å¹¶ä½¿ç¨Right å½æ°è·åByteåæ°æ®è½¬æ¢ä¸ºæ å两å符çåå è¿å¶å符串ã
1ï¼Hex å½æ°ï¼è¿å代表åå è¿å¶æ°å¼ç Stringã
2ï¼Byte æ°æ®ç±»åï¼Byte åéåå¨ä¸ºå精度åãæ 符å·æ´åã8 ä½ï¼1个åèï¼çæ°å¼å½¢å¼ï¼èå´å¨ 0 è³ 255 ä¹é´ã
3ï¼Right å½æ°ï¼è¿å Variant (String)ï¼å ¶ä¸å å«ä»å符串å³è¾¹ååºçæå®æ°éçå符ã
4ï¼åå è¿å¶ï¼åå è¿å¶ï¼è±æå称ï¼Hexadecimalï¼ï¼æ¯è®¡ç®æºä¸æ°æ®çä¸ç§è¡¨ç¤ºæ¹æ³ãåæ们æ¥å¸¸çæ´»ä¸ç表示æ³ä¸ä¸æ ·ãå®ç±0-9ï¼A-Fç»æï¼åæ¯ä¸åºå大å°åãä¸10è¿å¶ç对åºå ³ç³»æ¯ï¼0-9对åº0-9ï¼A-F对åº10-15ï¼Nè¿å¶çæ°å¯ä»¥ç¨0~(N-1)çæ°è¡¨ç¤ºï¼è¶ è¿9çç¨åæ¯A-Fã
5ï¼ä¸²å£æ¥æ¶å®é 代ç ï¼
Private Sub MSComm1_OnComm() 'æ¥æ¶æ°æ®Dim strBuff As String
Select Case MSComm1.CommEvent
Case 2
MSComm1.InputLen = 0
strBuff = MSComm1.Input
BytReceived() = strBuff
jieshou
lenInput = Len(strData)
'æ°æ®å¤ç代ç
End Select
End Sub
Public Function jieshou() 'æ¥æ¶æ°æ®å¤ç为16è¿å¶å符串
Dim i As Integer
For i = 0 To UBound(BytReceived)
If Len(Hex(BytReceived(i))) = 1 Then
strData = strData & "0" & Hex(BytReceived(i)) & " "
Else
strData = strData & Hex(BytReceived(i)) & " "
End If
Next
RichTextBox1.Text = strData
End Function
6ï¼VB6.0使ç¨CStr å½æ°å°ä¸Byteæ°å¼ï¼è½¬æ¢ä¸º Stringï¼ææ¬åï¼ã
CStr å½æ°ç¤ºä¾ï¼
Dim MyByte, MyString
MyByte =128 ' MyDouble 为 Byte æ°æ®ç±»åã
MyString = CStr(MyByte) ' MyString çå
容为â128âã
dim str as string
str=a.ToString
我需要把mscomm控件接收到的二进制数据存到一个字符型变量里
比如,我接收到 01 (串口定义以二进制数据传输) ,而我需要把它存到一个字符型变量如strbuff中,还以01显示出来
Private Sub Command1_Click()
Dim a As Byte
Dim s As String
a = &012
s = a
MsgBox s
End Sub
是这样吗?VB自动可以转换,但好像第一位是0转丢了
我就是要留下那个0,那个0也是我需要的
你QQ多少,请详细给我讲讲吧