-
Oct 20th, 2020, 07:49 AM
#1
Thread Starter
Addicted Member
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 ?
-
Oct 20th, 2020, 07:53 AM
#2
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
-
Oct 20th, 2020, 08:18 AM
#3
Re: Extended ascii characters
Here in the UK a simple Chr$(177) produces the Plus/Minus symbol.
-
Oct 20th, 2020, 08:34 AM
#4
Thread Starter
Addicted Member
Re: Extended ascii characters
Originally Posted by Zvoni
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 ?
-
Oct 20th, 2020, 08:45 AM
#5
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.
-
Oct 20th, 2020, 09:46 AM
#6
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
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>
-
Oct 20th, 2020, 09:55 AM
#7
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)
-
Oct 20th, 2020, 09:59 AM
#8
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
-
Oct 20th, 2020, 09:16 PM
#9
Fanatic Member
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.
-
Oct 21st, 2020, 07:53 AM
#10
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:
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.
-
Oct 21st, 2020, 08:10 AM
#11
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.
-
Oct 21st, 2020, 09:58 AM
#12
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
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.
-
Oct 21st, 2020, 02:23 PM
#13
New Member
Re: Extended ascii characters
Originally Posted by Eduardo-
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.
-
Oct 22nd, 2020, 03:47 AM
#14
Re: Extended ascii characters
Originally Posted by [citation-needed]
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.
-
Oct 22nd, 2020, 03:55 AM
#15
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
-
Oct 22nd, 2020, 09:36 AM
#16
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.
-
Oct 22nd, 2020, 10:00 AM
#17
Re: Extended ascii characters
Originally Posted by dilettante
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.
-
Oct 22nd, 2020, 10:13 AM
#18
Re: Extended ascii characters
Label.Caption allows font matching. TextBox.Text does not. That's the difference.
-
Oct 22nd, 2020, 10:17 AM
#19
Re: Extended ascii characters
Originally Posted by dilettante
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|