Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I view hex value for a byte? 1

Status
Not open for further replies.

cruicu

Technical User
Nov 25, 2002
24
RO
how can I view hex value for a byte received from serial interface?
thanks!
 
If using a MSComm control with InputMode set to binary then:

Dim vntTmp As Variant
dim intC1 As Integer

vntTmp = Comm1.Input
If IsArray(vntTmp) Then
For intC1 = LBound(vntTmp) To UBound(vntTmp)
Debug.Print Hex$(vntTmp(intC1))
Next
End If

Paul Bent
Northwind IT Systems
 
Paul,

I am using the code you provided to fill 2 fields to see what I am getting. All looks good execpt when I hit a HEX "0D" (or any other hex char that starts with a "0"), I am only getting the "D". It is suppressing the 0. Is there a way to keep this.

My input string in text looks like:
" G 99940 lb xx" - The xx here are hex 0D & 0A

My input string in Hex looks like:
"2047203939393430206C62DA"

*** I need the last 2 characters to be 0D 0A

vntTmp = MSComm1.Input
If IsArray(vntTmp) Then
For intC1 = LBound(vntTmp) To UBound(vntTmp)
Debug.Print Hex$(vntTmp(intC1))
frmShowInputString.Text1.Text = frmShowInputString.Text1.Text & Hex$(vntTmp(intC1))
frmShowInputString.Text2.Text = frmShowInputString.Text2.Text & Chr(vntTmp(intC1))
Next
End If
 
Have you tried using the format command?

frmShowInputString.Text1.Text = frmShowInputString.Text1.Text & (format (Hex$(vntTmp(intC1)), "00"))
 
Thanks for the answer. I tried the Format command but get the same results. I found a temp work-around that is probably not the best, but it is working for now. If anyone has any other ideas on the proper way to do this, that would be great. Thanks.

Here is my temp work around:
vntTmp = MSComm1.Input
If IsArray(vntTmp) Then
For intC1 = LBound(vntTmp) To UBound(vntTmp)
strWork = Hex$(vntTmp(intC1))
If Len(strWork) = 1 Then
strWork1 = "0" + strWork
Else
strWork1 = strWork
End If
Debug.Print strWork
' *** frmShowInputString.Text1.Text = frmShowInputString.Text1.Text & Hex$(vntTmp(intC1))
frmShowInputString.Text1.Text = frmShowInputString.Text1.Text & strWork1
Next
End If
 
If you want each number to be 2 characters...
You could also do this...

Code:
vntTmp = MSComm1.Input
If IsArray(vntTmp) Then
  For intC1 = LBound(vntTmp) To UBound(vntTmp)
    strWork = Right("0" & Hex$(vntTmp(intC1)), 2)
    Debug.Print strWork
    frmShowInputString.Text1 = frmShowInputString.Text1.Text & strWork
  Next
End If

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif

 
Cubee,

Thank you VERY much. That did it.

Amazing how much a newbie can do with all this knowledge here on Tek-Tips. Thanks to you all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top