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.
Printable View
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.
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
Now you call the above module by the following lines of code...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 each character is held in the array with the 1st being in tBytes(0) and the second in tBytes(1) and so on...VB Code:
Private Sub Form_Load() Dim tBytes() As Byte tBytes() = GetByteArray("Testing this array") End Sub
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.
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
damn!!
So short and precise...
Tanx for the compression CV, I prefer your own over mines...lol
And they work the same way too...
hey guys reallly thanks alot.....got to try them out later......hmmm.....i really got a long way to go......thanks!