Results 1 to 6 of 6

Thread: [RESOLVED] Text Box Contents to Byte Array?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2012
    Location
    Sydney
    Posts
    39

    Resolved [RESOLVED] Text Box Contents to Byte Array?

    Hi everyone, I'm absolutely new at programming and have been dabbling here and there with small code but I decided to make something useful and now can't seem to figure this out.

    I have a text box that I will paste into a byte array, for example:

    02 01 05 BF DD 03

    All I need to do is when I click on a button, for the program to take the length of the array and store it in RCVDMSG_Length() and then take the contents of the text box and put it into a byte array RCVDMSG().

    From there I think I can figure out how to manipulate the array... but it's this first step that I'm stuck on....

    So far I have this in my Form:

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
    
            Dim RCVDMSG() As Byte
            Dim RCVDMSG_Length() As Integer
            
            RCVDMSG_Length = Len(TextBox1.Text)
    Cheers

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Text Box Contents to Byte Array?

    So the TextBox will actually contains hexadecimal byte values, e.g. the TextBox.Text property will literally return "02 01 05 BF DD 03", correct?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2012
    Location
    Sydney
    Posts
    39

    Re: Text Box Contents to Byte Array?

    Hi there, yes, it will always have HEX input as in the example. No other type of information will be pasted there.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Text Box Contents to Byte Array?

    In that case you don't want to get the length first. You break up the data first and then get the length from the array. You can break the String up into substrings using the String.Split method. You can then go through the substrings, either with a loop or a LINQ query, and convert each substring to a Byte using the Convert.ToByte method, which allows you to specify that the String being converted is in base 2, 8, 10 or 16.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2012
    Location
    Sydney
    Posts
    39

    Re: Text Box Contents to Byte Array?

    Ok thanks mate, I'll have a go and see how it turns out. Cheers!

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2012
    Location
    Sydney
    Posts
    39

    Re: Text Box Contents to Byte Array?

    Hi there, I ended up using a CHAR array instead.. it's working for now so hopefully I can adapt it to my needs. Cheers.

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