Results 1 to 5 of 5

Thread: Coverting a string to an array of bytes

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    19

    Coverting a string to an array of bytes

    Hi All,

    I am having a hard time figuring out how to convert a string I get from the mscomm1.input to an array of bytes. I can't seem to figure out how to get a single byte from a string, then convert it to a byte. I can display the string I am receiving, but not as bytes.

    I am recieiving data through a bluetooth link and the comm port from the robot I am working on. What I want to do is to get the mscomm1.input string length, then loop through taking one character of the string, converting it to a byte, then storing it in an array of bytes.

    I just can't seem to figure out how to address individual characters in an array.

    Thanks for the help,

    Jonathan

    www.madlabs.info

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Humm humm... what is the current code you have for data input, before I start figuring this out?

  3. #3
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Look into Chr & Asc functions in MSDN

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    19
    It goes something like this:

    sData = MSComm1.Input

    This results in a string with 4 characters. The data is coming from a robot.

    Now, I want to convert the characters in the string to numbers, then store them in a byte array.

    What I can't seem to do is address and retrive the individual characters of the string, then put them in an array.

    Thanks,

    Jonathan

  5. #5
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Well, the easiest to go with:

    VB Code:
    1. Dim Buffer() As Byte
    2. Buffer = StrConv(MSComm1.Input, vbFromUnicode)
    3. Debug.Print "First byte: " & Buffer(0) & " | Number of bytes: " & (UBound(Buffer) + 1)

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