Confusing Chr$ explanation - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10) +---- Thread: Confusing Chr$ explanation (/showthread.php?tid=1820) |
Confusing Chr$ explanation - PhilOfPerth - 07-07-2023 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 RE: Confusing Chr$ explanation - CharlieJV - 07-07-2023 (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 What output are you expecting, and what output are you getting? RE: Confusing Chr$ explanation - PhilOfPerth - 07-07-2023 (07-07-2023, 01:31 AM)CharlieJV Wrote: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.(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 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! RE: Confusing Chr$ explanation - Space_Ghost - 07-07-2023 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)
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 RE: Confusing Chr$ explanation - PhilOfPerth - 07-07-2023 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? RE: Confusing Chr$ explanation - Space_Ghost - 07-07-2023 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
MORE DETAILS ON EXTENDED ASC II https://www.lookuptables.com/text/extended-ascii-table
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".
DIFFERENCE BETWEEN ANSI AND ASC II (not super important) http://www.differencebetween.net/technology/web-applications/difference-between-ansi-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. Finally be careful when inputting information in and what the text file encoding is, including Unicode and UTF-8, etc..... Cheers! image hosting RE: Confusing Chr$ explanation - PhilOfPerth - 07-07-2023 (07-07-2023, 04:52 AM)Space_Ghost Wrote: Hi PhilOfPerth, 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. RE: Confusing Chr$ explanation - Space_Ghost - 07-07-2023 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/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-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! RE: Confusing Chr$ explanation - PhilOfPerth - 07-08-2023 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. RE: Confusing Chr$ explanation - Space_Ghost - 07-08-2023 (07-08-2023, 12:47 AM)PhilOfPerth Wrote: Hi Space Ghost.My Pleasure !!! I myself worked through this not too long ago....glad I could help. Cheers. |