Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Confusing Chr$ explanation
#1
From the WIKI:        the CHR$ function returns the character associated with a certain character code as a STRING
                 and:        Valid ASCII code% numbers range from 0 to 255

So why does this not work:

For a = 129 To 255
Print a; Chr$(a)
Sleep 1: Cls: Next 

    Huh
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#2
(07-07-2023, 01:18 AM)PhilOfPerth Wrote: From the WIKI:        the CHR$ function returns the character associated with a certain character code as a STRING
                 and:        Valid ASCII code% numbers range from 0 to 255

So why does this not work:

For a = 129 To 255
Print a; Chr$(a)
Sleep 1: Cls: Next 

    Huh

What output are you expecting, and what output are you getting?
Reply
#3
(07-07-2023, 01:31 AM)CharlieJV Wrote:
(07-07-2023, 01:18 AM)PhilOfPerth Wrote: From the WIKI:        the CHR$ function returns the character associated with a certain character code as a STRING
                 and:        Valid ASCII code% numbers range from 0 to 255

So why does this not work:

For a = 129 To 255
Print a; Chr$(a)
Sleep 1: Cls: Next 

    Huh

What output are you expecting, and what output are you getting?
 I WAS getting nothing for a second or two, then a giant symbol, then crashed; But now, I get what I expected, each char in turn with its code. 
I suspect there was something hanging in my computer that shouldn't be there, but I had nothing else open. 
Sorry, looks like my problem!  Blush
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#4
Hi PhilOfPerth,

I am guessing that you want to print out the numbers from 129 to 255 and next to each one the ASC II character.  There are actually multiple ways to do this and I am going to continue with my assumptions.  You did not DIM your VAR a so it is a SINGLE (a decimal).  I would DIM a as an integer.  Then since PRINT needs a string you can cast the INTEGER to a string with STR$.  Finally you could use a comma (giving you a tab), a semicolon (giving no space), or a + (same as semicolon but concats together).  I chose a comma.

So....CHR$(a) was/is a string, but (a) was a SINGLE in your code so you need to convert it to a string so you can use PRINT at the same time for both (a) and CHR$(a).

I mean this sincerely, BASIC in general is one of the most powerful languages for string manipulations (along with Perl).

Here is the code
Code: (Select All)
$CONSOLE:ONLY
OPTION _EXPLICIT
CLS
DIM a AS INTEGER
FOR a = 129 TO 255
    PRINT STR$(a), CHR$(a)
NEXT a

Here is the output to the console
129    ü
130    é
131    â
132    ä
133    à
134    å
135    ç
136    ê
137    ë
138    è
139    ï
140    î
141    ì
142    Ä
143    Å
144    É
145    æ
146    Æ
147    ô
148    ö
149    ò
150    û
151    ù
152    ÿ
153    Ö
154    Ü
155    ¢
156    £
157    ¥
158    ₧
159    ƒ
160    á
161    í
162    ó
163    ú
164    ñ
165    Ñ
166    ª
167    º
168    ¿
169    ⌐
170    ¬
171    ½
172    ¼
173    ¡
174    «
175    »
176    ░
177    ▒
178    ▓
179    │
180    ┤
181    ╡
182    ╢
183    ╖
184    ╕
185    ╣
186    ║
187    ╗
188    ╝
189    ╜
190    ╛
191    ┐
192    └
193    ┴
194    ┬
195    ├
196    ─
197    ┼
198    ╞
199    ╟
200    ╚
201    ╔
202    ╩
203    ╦
204    ╠
205    ═
206    ╬
207    ╧
208    ╨
209    ╤
210    ╥
211    ╙
212    ╘
213    ╒
214    ╓
215    ╫
216    ╪
217    ┘
218    ┌
219    █
220    ▄
221    ▌
222    ▐
223    ▀
224    α
225    ß
226    Γ
227    π
228    Σ
229    σ
230    µ
231    τ
232    Φ
233    Θ
234    Ω
235    δ
236    ∞
237    φ
238    ε
239    ∩
240    ≡
241    ±
242    ≥
243    ≤
244    ⌠
245    ⌡
246    ÷
247    ≈
248    °
249    ∙
250    ·
251    √
252    ⁿ
253    ²
254    ■
255
Reply
#5
Thanks Space Ghost.
That was the output I was looking for, and I get the same results now.
Bu what brought me to write these few lines is that I was trying to compare this output to the ASCII (and extended ASCII) characters list, and some of these don't match up.

Some examples (and there are others) are: 
In the ASCII list, char 169 is the registered trademark symbol), 173 is an inverted i , 184 is  the copyright symbol, and 248 is 3/4 .

Does QB use a different character list?
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#6
Hi PhilOfPerth,

Here are some resources that I found very helpful for ASC II and Extended ASC II -- and ALT Codes.  I recommend you read and review in order.

OVERVIEW TABLE OF BOTH ASC II AND EXTENDED ASC II
https://www.asciitable.com/

MORE DETAILS ON ASC II
https://www.lookuptables.com/text/ascii-table
  • ASCII was originally created as a standard for sending text over phone lines, and first used with teleprinters back in 1963. It consists of 128 characters (7 bit).
  • Every ASCII character has an equivalent number, often used in programming languages such as Python.
  • The first 32 ASCII characters (0-31) and 127 (DEL) are actually commands historically used to control the teleprinter, such as the well known carriage return (13) and line feed (10). For this reason they are referred to as control characters, control codes or non printable characters.
  • The remainder of the 128 ASCII characters are the visible / printable characters most people would equate to plain text. These printable characters are often referred to as the ASCII Standard Character Set and include upper case letters, lower case letters, numbers and basic punctuation.

MORE DETAILS ON EXTENDED ASC II
https://www.lookuptables.com/text/extended-ascii-table
  • There are well over 200 different "extended" (8 bit) versions of the ASCII character set.
  • Extended ASCII provides 256 characters, the extended part making up characters 128-255.
  • Various extended versions have been developed for different purposes such as to support proprietary technology, different alphabets, or simply to draw nice boxes on the screen.
  • Below is the CP437 (Code Page 437) version which was present on the original IBM PC, based on characters used in Wang word processing machines.
  • This particular set of extended ASCII characters are sometimes referred to as ALT Codes because in Windows it is possible to hold down the ALT key and type the 3 digit ASCII code on the number pad to output a character not physically present on the keyboard.

ALT CODES (IMPORTANT)
https://www.lookuptables.com/text/alt-codes
Please note that the first two rows of codes in the QB64pe ASC II table are what are called "ALT Codes".
  • There are some characters that are not present on the keyboard, so to be able to 'type' them isn't straight forward. Here are your options:
  • Windows Character Map
  • Press the Windows key and type Character Map - here you can find all the characters visually if you know the Character Set they belong to.
  • Use Alt Codes - Keyboard Shortcuts
  • Use numeric shortcuts known as ALT Codes - Simply:
  • Make sure Num Lock is ON
  • Hold down the ALT Key
  • Type the relevant number on the numeric keypad
  • Release the ALT key
  • * These should work if your system locale is set to English (United States).

DIFFERENCE BETWEEN ANSI AND ASC II (not super important)
http://www.differencebetween.net/technol...and-ascii/


You can see the QB64pe ASC II Chart under the IDE Tools Menu --> ASC II Chart, here is the image that comes up.  Note it uses the ALT codes for the "non-printable" 1 to 32 first items.

[Image: 01.png]

Finally be careful when inputting information in and what the text file encoding is, including Unicode and UTF-8, etc.....

Cheers!

image hosting
Reply
#7
(07-07-2023, 04:52 AM)Space_Ghost Wrote: Hi PhilOfPerth,

Here are some resources that I found very helpful for ASC II and Extended ASC II -- and ALT Codes.  I recommend you read and review in order.

OVERVIEW TABLE OF BOTH ASC II AND EXTENDED ASC II
https://www.asciitable.com/

MORE DETAILS ON ASC II
https://www.lookuptables.com/text/ascii-table
  • ASCII was originally created as a standard for sending text over phone lines, and first used with teleprinters back in 1963. It consists of 128 characters (7 bit).
  • Every ASCII character has an equivalent number, often used in programming languages such as Python.
  • The first 32 ASCII characters (0-31) and 127 (DEL) are actually commands historically used to control the teleprinter, such as the well known carriage return (13) and line feed (10). For this reason they are referred to as control characters, control codes or non printable characters.
  • The remainder of the 128 ASCII characters are the visible / printable characters most people would equate to plain text. These printable characters are often referred to as the ASCII Standard Character Set and include upper case letters, lower case letters, numbers and basic punctuation.

MORE DETAILS ON EXTENDED ASC II
https://www.lookuptables.com/text/extended-ascii-table
  • There are well over 200 different "extended" (8 bit) versions of the ASCII character set.
  • Extended ASCII provides 256 characters, the extended part making up characters 128-255.
  • Various extended versions have been developed for different purposes such as to support proprietary technology, different alphabets, or simply to draw nice boxes on the screen.
  • Below is the CP437 (Code Page 437) version which was present on the original IBM PC, based on characters used in Wang word processing machines.
  • This particular set of extended ASCII characters are sometimes referred to as ALT Codes because in Windows it is possible to hold down the ALT key and type the 3 digit ASCII code on the number pad to output a character not physically present on the keyboard.

ALT CODES (IMPORTANT)
https://www.lookuptables.com/text/alt-codes
Please note that the first two rows of codes in the QB64pe ASC II table are what are called "ALT Codes".
  • There are some characters that are not present on the keyboard, so to be able to 'type' them isn't straight forward. Here are your options:
  • Windows Character Map
  • Press the Windows key and type Character Map - here you can find all the characters visually if you know the Character Set they belong to.
  • Use Alt Codes - Keyboard Shortcuts
  • Use numeric shortcuts known as ALT Codes - Simply:
  • Make sure Num Lock is ON
  • Hold down the ALT Key
  • Type the relevant number on the numeric keypad
  • Release the ALT key
  • * These should work if your system locale is set to English (United States).

DIFFERENCE BETWEEN ANSI AND ASC II (not super important)
http://www.differencebetween.net/technol...and-ascii/


You can see the QB64pe ASC II Chart under the IDE Tools Menu --> ASC II Chart, here is the image that comes up.  Note it uses the ALT codes for the "non-printable" 1 to 32 first items.

[Image: 01.png]

Finally be careful when inputting information in and what the text file encoding is, including Unicode and UTF-8, etc.....

Cheers!

image hosting

Thanks.
I have read through those references, and the Extended Asc II list seems to reflect the list used with PE.
It's different from the "old" ASCII codes lists that I found. 
It's missing a few symbols that I think must still be available somewhere - the Copyright, and Registered Trademark for instance - as they're still fairly popular..
These were listed as 184 and 169 in the old lists but I don't see them in Extended Asc II.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#8
Hi PhilOfPerth,

The copyright and trademark (TM) and also (R) are in the ALT Codes.  Click on the ALT Codes link I provided and scroll to the end.  There are multiple tables of historic ALT codes that are system specific.  Everyone uses UNICODE now.  NOTE WELL, some have leading zeros and you will find your TM, (C), and (R), with leading zeros.  

ALT 0153 ™ Trade Mark Sign
ALT 0169 © Copyright Sign
ALT 0174 ® Registered Sign

Also, here is a moderately detailed history lesson (it is actually much deeper than this...yikes!): https://www.joelonsoftware.com/2003/10/0...o-excuses/

Here is a very nice video that explains ASC II and Extended ASC II and UNICODE: https://www.youtube.com/watch?v=I-pQH_krD0M

Cheers!
Reply
#9
Hi Space Ghost.
I said I'd read through the references you gave me, but I lied - I skipped the Alt Codes one, as I thought these were just Windows inventions.
Seems like they are, but they're the only way to get some characters that aren't in the ASCII and Unicode lists. 
Thanks for the explanations and references, it's much clearer now.  Smile
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#10
Thumbs Up 
(07-08-2023, 12:47 AM)PhilOfPerth Wrote: Hi Space Ghost.
I said I'd read through the references you gave me, but I lied - I skipped the Alt Codes one, as I thought these were just Windows inventions.
Seems like they are, but they're the only way to get some characters that aren't in the ASCII and Unicode lists. 
Thanks for the explanations and references, it's much clearer now.  Smile
My Pleasure !!! I myself worked through this not too long ago....glad I could help. Cheers.
Reply




Users browsing this thread: 6 Guest(s)