-
January 1st, 2010, 01:22 AM
#1
How to Convert ASCII to Hex?
[ Merged ]
Here's my code and the result, as much as I know, is in ASCII:
Code:
Private Sub Form_Load()
With MSComm1
.CommPort = 1
If .PortOpen = False Then
.PortOpen = True
End If
.DTREnable = True
.InputLen = 1
.RThreshold = 1
.Settings = "9600,n,8,1"
End With
End Sub
Private Sub MSComm1_OnComm()
Dim inbuffer() As Byte 'Declare an array of bytes
Dim i As Long
Select Case Me.MSComm1.CommEvent
Case comEvReceive
ReDim inbuffer(Me.MSComm1.InBufferCount) 'Specify the size of the array. InBuffercount gives the number of characters in the InputBuffer
inbuffer = Me.MSComm1.Input 'Read the InputBuffer
For i = 0 To UBound(inbuffer) 'Ubound(inbuffer) gives the upper bound of the array, which is equal to the number of characters in the InputBuffer
Me.Text1.Text = Me.Text1.Text & Chr$(inbuffer(i)) 'TxtReceive is a text box
Next i
End Select
End Sub
I need the data to be in Hex so please lend a hand. Thanks.
Last edited by WizBang; January 2nd, 2010 at 07:48 AM.
Reason: Added [code] tags
-
January 1st, 2010, 04:44 PM
#2
Re: How to Convert Hex to ASCII?
inBuffer contains the data. what's the problem? You don't need to convert anything to text
-
January 2nd, 2010, 02:29 AM
#3
Re: How to Convert Hex to ASCII?
Actually the title is wrong. I need to convert it to hex (or decimal, etc) because the result is in ASCII. If I use the data I receive (which is in ASCII), I simply can't use it to make a command because it seems that VB6 can't comprehend the characters. Here's what I get and what I need to convert:
AlÿÃ`ZûB
So at least, in any number system excpet that. Thanks!
-
January 2nd, 2010, 02:52 AM
#4
Re: How to Convert Hex to ASCII?
-
January 2nd, 2010, 07:24 AM
#5
Re: How
[ Merged ]
Try Hex$(YourData)
Last edited by WizBang; January 2nd, 2010 at 07:49 AM.
Reason: Merged thread
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
January 2nd, 2010, 07:56 PM
#6
Re: How to Convert ASCII to Hex?
To be more prcise:
Code:
Me.Text1.Text = Me.Text1.Text & Hex$(inbuffer(i))
But I have an idea, this is not quite what you wanted...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|