CHR (127 to 159) is always

Discussion in 'Questions (Windows Mobile)' started by schimanski, May 20, 2009.

  1. schimanski

    schimanski Well-Known Member Licensed User

    Hello!

    I have a problem with the return from ASCII characters by a given number.
    With the command CHR(integer), I always get the character



    for the numbers 127 to 159.
    Where is the mistake?

    Thanks for answer....
     
  2. agraham

    agraham Expert Licensed User

  3. schimanski

    schimanski Well-Known Member Licensed User

    Thanks agraham!

    But now, I have a problem: I need the displayable characters between chr 127 and 160. Is there a way to show the ANSI-charakters? The reason is, that I have to change decimal numbers in a character and send the string to a server, which works with ascii/ansi. Because the characters between 127 and 160 can't displayed in unicode, the server can't decode the string.

    Thanks for anwer...
     
  4. agraham

    agraham Expert Licensed User

    There are no displayable characters between 127 and 160 in Unicode, they are not valid code points (values). However 8bit character code pages do usually have displayable characters from 127 to 255 but they all differ so you need to know which code page is assumed before you know what the character codes between 127 and 255 are meant to represent. Note that ASCII only defines printable characters between 32 and 127. I don't know if it is formally standardised as such but the "ANSI" code page is probably 1252.

    That's not the reason. Unicode incorporates every printable character in use in the world today, and a lot that are of only historic interest as well. You don't say how you are sending the string to the server but the Unicode code points in Basic4ppc (.NET) will need converting to the code page that the server understands so that when you specify a character inside Basic4ppc it will be converted to the code page value that the server understands.

    You can do this with BinaryFile.StringToBytes to get an array of bytes (8bit characters) converted from a string to the code page specified when you initialized a BinaryFile object with New2. You can then send the contents of the array to the server. My BytesConverter library can do similar conversions and can also read and write converted data from and to files directly rather than using the BinaryFile methods as an intermediate stage. There is a list of code page numbers in the ByesConverter help.

    If you want to read strings from your server you will need to convert in the opposite direction from the server code page to Unicode.
     
  5. schimanski

    schimanski Well-Known Member Licensed User

    Thanks for your answer, agraham!

    But there is one thing, that I didn't understand! The ANSI-Codepage is 1252. When I use your BytesConverter, I get with the CodePageFileDemo for the codepage 1252 the following characters:

    Code:
    @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
    `abcdefghijklmnopqrstuvwxyz{|
    }~
    ???????????????????????????
    *¡¢£¤¥¦§¨©ª«¬*®¯°±²³´µ¶·¸¹º»¼½¾¿
    ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß
    àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
    AaAaAaCcCcCcCcDdÐdEeEeEeEeEeGgGg
    But the ANSI-Code I need is this:

    Code:
    @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
    `abcdefghijklmnopqrstuvwxyz{|
    }~
    €‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ
    *¡¢£¤¥¦§¨©ª«¬*®¯°±²³´µ¶·¸¹º»¼½¾¿
    ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß
    àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
    Why can I only get a "?" for the characters between 127 and 160?:confused::confused:
     
  6. agraham

    agraham Expert Licensed User

    Same boring old reason. The string being written is a UTF16 string with invalid codepoints between 127 and 160 where Unicode has no characters defined. These are being replaced by question marks in the specified code page as they don't represent any characters. If instead you write the binary codes they will read back interpreted by whatever codepage you specify in Sub ReadCodePage, try 437 and 1252 and see the difference.

    Code:
    Sub WriteCodePage
      FileOpen(f1, AppPath & 
    "\codepage.txt", cRandom)   
      
    For i = 32 To 255
        FilePutByte(f1, i-
    32, i)
      
    Next   
      FileClose(f1)   
    End Sub
     
  7. schimanski

    schimanski Well-Known Member Licensed User

    Sorry for the circumstancess...:sign0013:

    But this is what I´m looking for to display the ANSI-characters between 127 an 160.

    Code:
    Dim buffer(5As byte

    Sub App_Start
       buffer(
    0)=131
       FileOpen(c1,
    "data.txt",cRandom)
       bin.New2(c1,
    1252)
       
    Msgbox(bin.BytesToString(buffer(),0,1))
    End Sub
    I'm slow-witted.:BangHead:....
     
  8. RandomCoder

    RandomCoder Well-Known Member Licensed User

  9. agraham

    agraham Expert Licensed User

    I don't see the problem :confused:. That code fragment looks fine to me. It takes a byte value, assumed to be a codepage 1252 character value and converts it to a Unicode value - the following amendment shows the ANSI value, the character represented by that value and the Unicode value for that character.

    Code:
    Sub App_Start
       buffer(
    0)= 128
       FileOpen(c1,
    "data.txt",cRandom)
       bin.New2(c1,
    1252)
       char = bin.BytesToString(buffer(),
    0,1)
       msg = 
    "ANSI value " & buffer(0) & " is character  " & char & "  is Unicode value " & Asc(char)
       
    Msgbox(msg)
    End Sub
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice