Results 1 to 8 of 8

Thread: Extended ASCII

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    68

    Extended ASCII

    I need some help getting ASC to return the same number in Far East Locales (where they use 2 bytes / char) as in other Locales for the Extended ASCII table. I am thinking of writing a function that return the ASC and if it is invalid (< 0 or > 255) then replace with valid number. Is there a better way to get around the issue? Where can I get a table of ASCII return codes in the Far East?

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Extended ASCII

    I think you mean Unicode:
    VB Code:
    1. strText = StrConv(MyString, vbUnicode)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    68

    Re: Extended ASCII

    Here is the code I am using
    VB Code:
    1. For x = 1 To Len(txt)
    2.     tmp = Asc(Mid(txt, x, 1))
    3.     ...
    4. Next
    Under most systems the proper ASCII return code is returned, but under Far East, it returns negative integers for the extended chars. I think I tried converting but it didn't work, maybe I did s/t wrong. Any help appreciated!
    Please note, the strings are stored in non-unicode format (one byte/char)

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    68

    Re: Extended ASCII

    Here is some more info, the strings are loaded from a binary file and are in ASCII format. I need to properly get the ASC value of each of the chars in the string in all locales. The strings do not contain anything past ASCII value 255 independent of the locale of the system!

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    68

    Re: Extended ASCII

    bump

  6. #6
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228

    Re: Extended ASCII

    What I've decided might work is if you convert the two bytes to binary, concantenate them, and then convert them back to decimal, you might get the "Extended ASCII" value you are looking for. Here's the code:
    VB Code:
    1. 'Usage: Bin2Dec(BINARY HERE) (returns decimal number)
    2. Function Bin2Dec(ByVal sBinary As String) As Long
    3.     For i = 0 To Len(sBinary) - 1
    4.         If Mid(sBinary, Len(sBinary) - i, 1) = "1" Then Bin2Dec = Bin2Dec + (2 ^ i)
    5.     Next
    6. End Function
    7.  
    8. 'Usage: Dec2Bin(NUMBER HERE) (returns binary)
    9. Public Function Dec2Bin(myNum As Variant) As String
    10.     Dim loopcounter As Integer
    11.     If myNum >= 2 ^ 31 Then
    12.         Dec2Bin = "Too big"
    13.         Exit Function
    14.     End If
    15.     Do
    16.         If (myNum And 2 ^ loopcounter) = 2 ^ loopcounter Then
    17.             Dec2Bin = "1" & Dec2Bin
    18.             Else
    19.             Dec2Bin = "0" & Dec2Bin
    20.         End If
    21.         loopcounter = loopcounter + 1
    22.     Loop Until 2 ^ loopcounter > myNum
    23.     If Len(Dec2Bin) / 2 <> Int(Len(Dec2Bin) / 2) Then Dec2Bin = "0" & Dec2Bin
    24. End Function
    25.  
    26. Public Function ExtendedAsc(Byte1 As String, Byte2 As String) As Long
    27.     Dim Bytes As String
    28.     Bytes = Dec2Bin(Asc(Byte1)) & Dec2Bin(Asc(Byte2))
    29.     ExtendedAsc = Bin2Dec(Bytes)
    30. End Function

    Now how this would work is:
    VB Code:
    1. Dim tmp As Long
    2. For x = 1 To Len(txt) Step 2
    3.     tmp = ExtendedAsc(Mid(txt, x, 1), Mid(txt, x+1, 1))
    4. Next
    Try it. This may or may not work, but give it a try!
    Luke

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    68

    Re: Extended ASCII

    The original is in binary already, it is saved in binary file format. When read from file it is stored in a string, maybe this is my mistake, dunno. The length of the txt is being returned properly, LenB return double the amt. Do you want me to use MidB instead?? I will try anyhow.
    Last edited by microalps; May 15th, 2005 at 12:06 PM.

  8. #8
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228

    Re: Extended ASCII

    Well, what my method does is it converts the 16 bits of data into decimal as opposed to the regular 8. You know, for your two-byte ASCII values.
    Luke

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