CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2010
    Posts
    2

    Exclamation 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

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How to Convert Hex to ASCII?

    inBuffer contains the data. what's the problem? You don't need to convert anything to text
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jan 2010
    Posts
    2

    Thumbs up 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!

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: How to Convert Hex to ASCII?

    Look up the Hex function

  5. #5
    Join Date
    Dec 2001
    Posts
    6,332

    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?

  6. #6
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    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
  •  





Click Here to Expand Forum to Full Width

Featured