Results 1 to 4 of 4

Thread: Help! StringToByteArray (StrConv Replaecment)

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    13

    Help! StringToByteArray (StrConv Replaecment)

    hello..

    as you know StrConv don't work fine when "language for Non-Unicode characters" option is set to any thing other than english.

    so, if you want to convert string to byte array using this it won't work
    bytTEMP = StrConv(strTEMP, vbFromUnicode)

    one solution i found after 4 hours of searching was putting LocaleID parameter
    specific for the non-unicode language you set..

    so this way it will work..
    bytTEMP = StrConv(strTEMP, vbFromUnicode, LocalID)

    you can get your LocalID from this list :
    http://support.microsoft.com/?kbid=221435

    but this solution is not practical since there is no function as i know to retrieve LocalID and pass it to the StrConv before Converting

    any help will be greatly appreciated

  2. #2
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: Help! StringToByteArray (StrConv Replaecment)

    These two APIs may be of use. They both return 1033 for my box (USA, English)

    Code:
    Private Declare Function GetUserDefaultLCID Lib "kernel32.dll" () As Long
    Private Declare Function GetSystemDefaultLCID Lib "kernel32.dll" () As Long

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Help! StringToByteArray (StrConv Replaecment)

    It is far from clear what you really want to accomplish.

    Even if you do a conversion using StrConv() and a different non-default locale all that gets you is the ANSI characters that the String maps to for that locale. What do you plan to do with them after that?

    Post #2 here shows how to retrieve the current user or system default locale, but using those does the same thing as letting the locale argument default.

    Ther is no API call to "guess what you mean and return the locale." The LCID is the way you say what Unicode to ANSI mapping you want.


    I'm not sure why it took you 4 hours to find this since it is right there in the VB6 manual, but without some explanation of what you want to accomplish I don't think we can help you much.

    I'm guessing this has something to do with either data persisted to disk or communicated over the Internet. In either case you might consider using the native format in VB6 (UTF-16) or converting to another Unicode encoding (UTF-8?).

  4. #4
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Help! StringToByteArray (StrConv Replaecment)

    Write your code to work with Unicode data and you have no problem. You should use StrConv only if you know you're dealing with ANSI data of user's locale. Using it for anything else is prone to errors.

    Basically this statement is the same as the UTF-16 or UTF-8 suggestion by dilettante.

Tags for this Thread

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