Results 1 to 2 of 2

Thread: Byte versus String*1 ??

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Post

    I got Type Mismatch error using code similar to the following.

    Dim Xbyte as Byte
    Dim Xstring as String
    Dim OneByte as String*1

    Xbyte = Left(Xtring, 1)
    Xbyte = OneByte


    I thought that Strings were made up of Bytes, and that a Byte was equivalent to a string of length one. I understand that VB might require more than one byte of storage for a string of length one (due to control data for string), but was surprised at Type Mismatch error.

    Apparently, I have been manipulating strings without understanding much about them.

    Any explanations?

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    VB uses Unicode to manipulate Strings, this means that it uses 2 bytes for each character, to assign a Single Char String to a Byte Variable do the following:
    Code:
    Dim sByte As String * 1
    Dim bByte() As Byte
    
    sByte = "A"
    bByte = StrConv(sByte, vbFromUnicode)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width