|
-
May 3rd, 2005, 07:52 PM
#1
Thread Starter
Lively Member
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?
-
May 3rd, 2005, 07:56 PM
#2
Re: Extended ASCII
I think you mean Unicode:
VB Code:
strText = StrConv(MyString, vbUnicode)
-
May 3rd, 2005, 07:59 PM
#3
Thread Starter
Lively Member
Re: Extended ASCII
Here is the code I am using
VB Code:
For x = 1 To Len(txt)
tmp = Asc(Mid(txt, x, 1))
...
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)
-
May 3rd, 2005, 09:04 PM
#4
Thread Starter
Lively Member
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!
-
May 15th, 2005, 08:21 AM
#5
Thread Starter
Lively Member
-
May 15th, 2005, 10:59 AM
#6
Frenzied Member
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:
'Usage: Bin2Dec(BINARY HERE) (returns decimal number)
Function Bin2Dec(ByVal sBinary As String) As Long
For i = 0 To Len(sBinary) - 1
If Mid(sBinary, Len(sBinary) - i, 1) = "1" Then Bin2Dec = Bin2Dec + (2 ^ i)
Next
End Function
'Usage: Dec2Bin(NUMBER HERE) (returns binary)
Public Function Dec2Bin(myNum As Variant) As String
Dim loopcounter As Integer
If myNum >= 2 ^ 31 Then
Dec2Bin = "Too big"
Exit Function
End If
Do
If (myNum And 2 ^ loopcounter) = 2 ^ loopcounter Then
Dec2Bin = "1" & Dec2Bin
Else
Dec2Bin = "0" & Dec2Bin
End If
loopcounter = loopcounter + 1
Loop Until 2 ^ loopcounter > myNum
If Len(Dec2Bin) / 2 <> Int(Len(Dec2Bin) / 2) Then Dec2Bin = "0" & Dec2Bin
End Function
Public Function ExtendedAsc(Byte1 As String, Byte2 As String) As Long
Dim Bytes As String
Bytes = Dec2Bin(Asc(Byte1)) & Dec2Bin(Asc(Byte2))
ExtendedAsc = Bin2Dec(Bytes)
End Function
Now how this would work is:
VB Code:
Dim tmp As Long
For x = 1 To Len(txt) Step 2
tmp = ExtendedAsc(Mid(txt, x, 1), Mid(txt, x+1, 1))
Next
Try it. This may or may not work, but give it a try!
-
May 15th, 2005, 11:54 AM
#7
Thread Starter
Lively Member
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.
-
May 15th, 2005, 06:41 PM
#8
Frenzied Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|