I need to put a byte array of ASCII character codes into a standard VB string.
Any ideas?
so . ..
MyString = MyBytes()
would be the assignment I would like to achieve. The above code doesn't work, of course!
Cheers chaps
Printable View
I need to put a byte array of ASCII character codes into a standard VB string.
Any ideas?
so . ..
MyString = MyBytes()
would be the assignment I would like to achieve. The above code doesn't work, of course!
Cheers chaps
This any good?
VB Code:
Dim i As Long Dim MyBytes() As Byte Dim strString As String For i = 0 To UBound(MyBytes) strString = strString & MyBytes(i) Next i MsgBox strString
The application I am trying to do is buffered screen displays. So for instance I have a console window of 78 x 50. This is displayed in a text box, so really I am trying to assign the byte array (2 dimensional) to the .Text property of the textbox.
I currently do it the way you suggest, but to me it feels clumsy. I have tried CopyMemory (Aka RtlMoveMemory) but this doesn't appear to work.
I really need more ideas . . .
You cannot CopyMemory to the .Text property because it is actually the argument of a function, not a string array.
Chrisjk gave you a good answer. Consider locking update on the control while you're moving stuff in there. Speeds things up a lot.
You can use this function to copy a byte array to a string.
DataSize = Length of string
Hope this helps,Code:Public Function GetString(ByRef Data() As Byte, ByVal DataSize As Long) As String
GetString = Space$(DataSize)
CopyMemory ByVal GetString, Data(0), DataSize
End Function
Pieter
I've got it working on one dimensional bytes arrays - but not on two dimensions.
I really want to use RtlMoveMemory, I just can't figure out how to coerce the damn array in.
[When I said .Text, it was for clarity - I put it in a local string first]
I am now using the 'TextOut' API function. This allows direct mappings of strings to DC's
Perfect.
Cheers for your help