Results 1 to 19 of 19

Thread: Extended ascii characters

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    231

    Extended ascii characters

    I want to display in a text box the symbol ±, next to some words.
    It's supposed to be the ascii chracter 241 but in the ASCII set of my computer 241 is the small Greek rho (displays here as ñ when I paste it, n tildal !).
    Anyway, in case all those symbols appear diffferent to you, what I want to display is the "plus or minus" symbol.
    How can I do this in VB6 without changing the computer's ANSI set ?

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,414

    Re: Extended ascii characters

    Eh? How do you figure it's supposed to be 241?
    On my machine (Germany) the "±" is: ALT+0177
    https://www.ascii-code.com/
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3
    Fanatic Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    578

    Re: Extended ascii characters

    Here in the UK a simple Chr$(177) produces the Plus/Minus symbol.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    231

    Re: Extended ascii characters

    Quote Originally Posted by Zvoni View Post
    Eh? How do you figure it's supposed to be 241?
    On my machine (Germany) the "±" is: ALT+0177
    https://www.ascii-code.com/
    Aber ja !
    I got it as 177 too (Griechenland).

    However here it says 241, for the standard ASCII set:

    http://asciiset.com/

    But I think that something rather mysteriously changes here. I 'm not sure. I said 241 produces the rho but yesterday it was something else.
    Also I do this:
    I copy-paste a table of numbers from a certain website and I use VB6 to add the numbers.
    Next to the numbers are some Greek words about which I don't care and they come out in VB6 as ????s. But sometimes they do come out as words ! What's the story ?

  5. #5
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: Extended ascii characters

    The problem with ASCII is that everything above character 127 isn't part of the ASCII standard, Extended ASCII isn't really a standard, it is a way that different ASCII encodings use the characters at positions 128 - 255. https://en.wikipedia.org/wiki/Extended_ASCII is a good overview of how this all works.


    This is why on Windows knowing which code page you are using is important - different code pages will cause different characters to be displayed for the same character codes.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Extended ascii characters

    Use ChrW$(&HB1&) instead. If you get a place-filler symbol ("?" or "☐") then your locale settings have left you in the cold.

    If you need it badly you'll need controls supporting Unicode or else draw the text using a W entrypoint like DrawTextW().


    Starting in Windows 10 1902 there is another option, though it has limitations.

    A program's application manifest can select UTF-8 as the ANSI codepage. With some fiddling you can then pass UTF-8 to some VB6 controls:

    Code:
    Option Explicit
    
    Private Const WM_SETTEXT = &HC&
    
    Private Declare Function SendMessageA Lib "user32" ( _
        ByVal hWnd As Long, _
        ByVal wMsg As Long, _
        ByVal wParam As Long, _
        ByVal lParam As Long) As Long
    
    Private Sub Form_Load()
        Dim Text As String
    
        Text = ChrB$(&HC2) & ChrB$(&HB1) & StrConv("123 ", vbFromUnicode) _
             & ChrB$(&HE2) & ChrB$(&H99) & ChrB$(&H82)
        SendMessageA Text1.hWnd, WM_SETTEXT, 0, StrPtr(Text)
    End Sub
    Name:  sshot.png
Views: 2260
Size:  788 Bytes

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
      <assemblyIdentity type="win32" name="Joeblow.Project1" version="1.0.0.0"/>
      <dependency>
        <dependentAssembly>
          <assemblyIdentity language="*" name="Microsoft.Windows.Common-Controls" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" type="win32" version="6.0.0.0" />
        </dependentAssembly>
      </dependency>
      <application>
        <windowsSettings>
          <activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
        </windowsSettings>
      </application>
    </assembly>

  7. #7
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Extended ascii characters

    without changing ansi/unicode?

    one trick could be to use + together with underscore + but u will need RichTextBox instead of textbox to make it work.

    example
    Code:
       RichTextBox1.Text = "Text + Text"
       RichTextBox1.SelStart = 5
       RichTextBox1.SelLength = 1
       RichTextBox1.SelUnderline = True
       RichTextBox1.SelLength = 0
       RichTextBox1.SelStart = Len(RichTextBox1.Text)

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Extended ascii characters

    Another thing to consider is the font in use, not all fonts use the same character for the same code.

    Terminal and sys fonts both use the expected ansi characters for each code 0-255

  9. #9
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    858

    Re: Extended ascii characters

    If you're using the net to locate ASCII tables, I've found over the years the extended set may differ by whoever is hosting the page/table. Caveat Emptor.

  10. #10
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: Extended ascii characters

    "Extended ASCII characters"

    Those words make me think of the old DOS days, or maybe even the TRS-80 days, where we actually had such a thing ... block/character graphics and a few extra characters to make the Spanish and French and maybe Germans happy.

    But these days, it's all about ANSI and codepages. Or, if you want to go to more than one-byte-per-character, we talk about Unicode, which is what VB6 strings are internally. And all of those things are mentioned above.

    Old Extended ASCII:
    Name:  EXT-ASC.gif
Views: 5910
Size:  6.0 KB

    To actually use that, you'll have to find a font that actually has that for its ANSI characters, and has it marked as the codepage you're using.
    Last edited by Elroy; Oct 21st, 2020 at 07:59 AM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  11. #11
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: Extended ascii characters

    One thing is the number that you need to type in the keyboard (Atl+Number) and another thing is the ANSI character number, the one that you need to use with Chr/ChrW.

    241 (Hex F1) is for the keyboard and 177 (Hex B1) is the ANSI code.

    How to explain that difference? I have no idea.

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Extended ascii characters

    There is more to mapping than you may think. Consider the Charset:

    Code:
    Option Explicit
    
    Private Const ANSI_CHARSET As Integer = 0
    Private Const SYMBOL_CHARSET As Integer = 2
    Private Const OEM_CHARSET As Integer = 255
    
    Private Sub DumpChars(ByVal Charset As Integer)
        Dim I As Integer
    
        Font.Charset = Charset
        For I = 33 To 126
            Print Chr$(I); " ";
            If (I - 33) Mod 32 = 31 Then Print
        Next
        Print: Print
        For I = 128 To 255
            Print Chr$(I); " ";
            If (I - 128) Mod 32 = 31 Then Print
        Next
        Print: Print
    End Sub
    
    Private Sub Form_Load()
        Caption = Font.Name
        DumpChars ANSI_CHARSET
        DumpChars SYMBOL_CHARSET
        DumpChars OEM_CHARSET
    End Sub
    Name:  sshot.png
Views: 3583
Size:  11.8 KB

    Note that font matching shifts into another font to pick up glyphs lacking in Courier New.
    Last edited by dilettante; Oct 21st, 2020 at 10:08 AM.

  13. #13
    New Member
    Join Date
    Apr 2020
    Posts
    12

    Re: Extended ascii characters

    Quote Originally Posted by Eduardo- View Post
    One thing is the number that you need to type in the keyboard (Atl+Number) and another thing is the ANSI character number, the one that you need to use with Chr/ChrW.

    241 (Hex F1) is for the keyboard and 177 (Hex B1) is the ANSI code.

    How to explain that difference? I have no idea.
    Alt codes have a complicated history in Windows, but if you prefix your alt+codes with a 0, you will (usually) get the matching Unicode character instead of a code-page-specific character.

  14. #14
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: Extended ascii characters

    Quote Originally Posted by [citation-needed] View Post
    Alt codes have a complicated history in Windows, but if you prefix your alt+codes with a 0, you will (usually) get the matching Unicode character instead of a code-page-specific character.
    Interesting (thanks), but still leaves many questions.

    I just realized that code page <> character set. Perhaps I'll study the issue at some point with more time.
    Here there is someone that explained a bit about it.

  15. #15
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: Extended ascii characters

    BTW, more weirdness:

    Code:
    Private Const OEM_CHARSET As Integer = 255
    
    Private Sub Command1_Click()
        Text1.Font.Charset = OEM_CHARSET
        Label1.Font.Charset = OEM_CHARSET
        
        Text1.Text = Chr(177)
        Label1.Caption = Chr(177)
    End Sub
    Name:  Untitled.png
Views: 2262
Size:  2.6 KB

  16. #16
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Extended ascii characters

    Assigning to Text1.Text does not permit font matching.

    Chose a font like Terminal that has that glyph and it works.

  17. #17
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: Extended ascii characters

    Quote Originally Posted by dilettante View Post
    Assigning to Text1.Text does not permit font matching.

    Chose a font like Terminal that has that glyph and it works.
    What I meant is that the TextBox displays different than the Label in the same conditions.

  18. #18
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Extended ascii characters

    Label.Caption allows font matching. TextBox.Text does not. That's the difference.

  19. #19
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: Extended ascii characters

    Quote Originally Posted by dilettante View Post
    Label.Caption allows font matching. TextBox.Text does not. That's the difference.
    I have no idea what font matching is, you are adding more confusion.

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