|
-
Jan 14th, 2012, 09:55 PM
#1
Thread Starter
Member
[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
-
Jan 14th, 2012, 10:23 PM
#2
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?
-
Jan 14th, 2012, 10:26 PM
#3
Thread Starter
Member
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.
-
Jan 14th, 2012, 10:56 PM
#4
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.
-
Jan 24th, 2012, 08:05 PM
#5
Thread Starter
Member
Re: Text Box Contents to Byte Array?
Ok thanks mate, I'll have a go and see how it turns out. Cheers!
-
Jan 25th, 2012, 12:39 AM
#6
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|