|
-
Feb 9th, 2003, 10:28 PM
#1
Thread Starter
New Member
convert string to byte array
hi guys,
is it possible to convert a string to a byte array?
if its possible how can it be done?
thanks and pardon me for my newbie question.
-
Feb 9th, 2003, 11:57 PM
#2
Hyperactive Member
Here it is... I assume that you know how to handle arrays, so here's the shortest version possible...
Put the following code in a module or a form or what not
VB Code:
Public Function GetByteArray(TextStr As String) As Variant
Dim ByteArray() As Byte
For xdat = 1 To Len(TextStr)
ReDim Preserve ByteArray(xdat - 1)
ByteArray(xdat - 1) = CByte(Asc(Mid$(TextStr, xdat, 1)))
Next xdat
GetByteArray = ByteArray
End Function
Now you call the above module by the following lines of code...
VB Code:
Private Sub Form_Load()
Dim tBytes() As Byte
tBytes() = GetByteArray("Testing this array")
End Sub
Now each character is held in the array with the 1st being in tBytes(0) and the second in tBytes(1) and so on...
NB... declaring the GetByteArray function as a Variant is simply because you can't pass array variables in functions as returned values... so you can only decare the function as a Variant and set it to the ByteArray variable array...
If you have anymore questions then post them aight....
Hope this helped you out.
If my post has been helpful, then please rate it accordingly...
If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.
-
Feb 10th, 2003, 12:09 AM
#3
VB has it's own string conversion function....
VB Code:
Private Sub Form_Load()
Dim tBytes() As Byte
tBytes() = StrConv("Testing this array", vbFromUnicode)
End Sub
-
Feb 10th, 2003, 12:23 AM
#4
Hyperactive Member
damn!!
So short and precise...
Tanx for the compression CV, I prefer your own over mines...lol
And they work the same way too...
If my post has been helpful, then please rate it accordingly...
If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.
-
Feb 10th, 2003, 06:28 AM
#5
Thread Starter
New Member
hey guys reallly thanks alot.....got to try them out later......hmmm.....i really got a long way to go......thanks!
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
|