Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleConvert a string into bytes and vice versa
DescriptionThis example shows how to convert a string into bytes and vice versa in Visual Basic 6.
Keywordsconvert, string, bytes, unicode
CategoriesStrings
 
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
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated