Senin, 30 Agustus 2010

How to Convert Byte To String In Visual Basic 6.0

This example shows how to convert a string into bytes and vice versa in Visual Basic 6.


To convert a string into bytes, use:
bytes = StrConv(txt, vbFromUnicode)
To convert an array of bytes into a string, use:

txt = StrConv(bytes, vbUnicode)
 
Private Sub cmdConvert_Click()
Dim txt As String
Dim bytes() As Byte
Dim i As Integer

' Display the bytes.
txt = txtOriginal.Text
bytes = StrConv(txt, vbFromUnicode)
txt = ""
For i = LBound(bytes) To UBound(bytes)
txt = txt & Format$(Hex$(bytes(i)), "00") & " "
Next i
txtBytes.Text = txt

' Convert back into a string.
txt = StrConv(bytes, vbUnicode)
txtResult.Text = txt
End Sub

Tidak ada komentar:

Posting Komentar