Click to See Complete Forum and Search --> : How to display the char whose ASCII value ranges from 1 to 31?
FreeOperator
May 15th, 2001, 12:31 AM
Dear all,
I am working on a VB program which allows the user to type in any chars whose ASCII values range from 1 to 255. But, it seems the TextBox or Rich Text Box that VB carries can NOT display some of the chars with ASCII values ranging from 1 to 31. For example, ATL+1 can not display the SOH char in the text box. But, I do have a program in hand whose text box can display SOH as a smilling face. I don't know what operation is taken behind the scene. Is there a way for my VB program to display those chars with ASCII value 1 to 31? Please advise and thanks in advance...
Tracy
Cimperiali
May 15th, 2001, 08:18 AM
as asc 0 to 32 are nonprintable ascii chars, I suppose they simply add a value to it
ie:
'pseudocode:
if ascii<32 then ascii = ascii+ 160
'try this and see if you can find images you saw in textbox:
'(remember that you can have different result from different fonts in use)
Private Sub Command1_Click()
Dim intx
For intx = 162 To 182
Print Chr(intx)
Next
End Sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
Kdev
May 15th, 2001, 08:28 AM
I'm not sure how to do this fully but here is something to consider. The textbox control and the richtextbox control do not display any characters for ascii values 1-31 but you can trap this key press with the keypress event like this:
private Sub Text1_KeyPress(KeyAscii as Integer)
If KeyAscii = 1 then
Text1.Text = Text1.Text & "%"
End If
End Sub
This will display a % anytime they press ALT+1
To get a smiley face or other such character I suppose that in a RichEdit TextBox you could probably do some tricky formating using wingding fonts or symbol fonts or something of the like.
There will be other considerations when doing such a procedure such as resetting cursor position and maintaing user settings but at least you get the idea I hope of how to trap such a key press and process it.
-K
Cakkie
May 15th, 2001, 08:59 AM
The main reason for these characters to exist goes back a long time. I'm gonna spare you the story and just say where it comes to.
A lot of those signs just can't be presented. Most of them have a special meaning for devices.
Try finding a sign to represent 'end of transmittion' or even a very common, the null character. Machines however don,t need to know how it looks, they just need to know which it is.
About giving them a special look, this is done by whatever processes the values. Take Word for example, send ALT+8 (which is Backspace). As you can see, that definitly isn't a backspace. Select the sign, and change fonts, you will see that some of them will just dispkay it as an empty square (meaning they can,t represent it). How do they know how to treat it, simple, they can see you are pressing the ALT key. If your not pressing the alt key, you wont get the char.
I did the test with vb, starting word, and adding chr(8) to the text. This showed up like a square (the one meaning he can't show it) However, when I used the sendkeys to send ALT+8, I got what I expected, the special sign.
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.