Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DAY 030: _CONTROLCHR
#1
Ever want to be able to see the ASCII characters that do things like eject the printer paper, CHR$(12)? Well with the keyword _CONTROLCHR OFF, you can! And if you act now, because we can't do this all day, we'll throw in _CONTROLCHR$ ON at no extra charge. Just pay separate shipping and handling.

SYNTAX _CONTROLCHR {OFF|ON}

Code: (Select All)
WIDTH 127, 20
_FONT 16
_KEYCLEAR
msg$ = "ASCII CHaracter Chart"
LOCATE 1, _WIDTH \ 2 - LEN(msg$) \ 2
PRINT msg$;
c = 1
_CONTROLCHR OFF
FOR i = 0 TO 255 ' There are 256 ASCII characters.
    i$ = LTRIM$(STR$(i))
    FOR j = 1 TO 2
        IF LEN(i$) < 3 THEN i$ = "0" + i$
    NEXT
    IF i AND i MOD (_HEIGHT - 4) = 0 THEN c = c + 8: LOCATE 3, c
    LOCATE i MOD (_HEIGHT - 4) + 3, c + 1: PRINT i$; " "; CHR$(i);
NEXT
SLEEP

_CONTROLCHR ON
_DELAY .5
FOR i = 1 TO _HEIGHT
    PRINT CHR$(13);
    _DELAY .2
NEXT

So now we have some nice symbols we can print to the screen for our text programs, which without this KEYWORD, would be used for the following...

Code: (Select All)
CTRL + A = CHR$(1)   ?  StartHeader (SOH)    CTRL + B = CHR$(2)   ?  StartText         (STX)
CTRL + C = CHR$(3)   ?  EndText     (ETX)    CTRL + D = CHR$(4)   ?  EndOfTransmit     (EOT)
CTRL + E = CHR$(5)   ?  Enquiry     (ENQ)    CTRL + F = CHR$(6)   ?  Acknowledge       (ACK)
CTRL + G = CHR$(7)   •  Bell        (BEL)    CTRL + H = CHR$(8)   ?  [Backspace]       (BSP)
CTRL + I = CHR$(9)   ?  Horiz.Tab   [Tab]    CTRL + J = CHR$(10)  ?  LineFeed(printer) (LF)
CTRL + K = CHR$(11)  ?  Vert. Tab   (VT)     CTRL + L = CHR$(12)  ?  FormFeed(printer) (FF)
CTRL + M = CHR$(13)  ?  [Enter]     (CR)     CTRL + N = CHR$(14)  ?  ShiftOut          (SO)
CTRL + O = CHR$(15)  ¤  ShiftIn     (SI)     CTRL + P = CHR$(16)  ?  DataLinkEscape    (DLE)
CTRL + Q = CHR$(17)  ?  DevControl1 (DC1)    CTRL + R = CHR$(18)  ?  DeviceControl2    (DC2)
CTRL + S = CHR$(19)  ?  DevControl3 (DC3)    CTRL + T = CHR$(20)  ¶  DeviceControl4    (DC4)
CTRL + U = CHR$(21)  §  NegativeACK (NAK)    CTRL + V = CHR$(22)  ?  Synchronous Idle  (SYN)
CTRL + W = CHR$(23)  ?  EndTXBlock  (ETB)    CTRL + X = CHR$(24)  ?  Cancel            (CAN)
CTRL + Y = CHR$(25)  ?  EndMedium   (EM)     CTRL + Z = CHR$(26)  ?  End Of File(SUB)  (EOF)

Note that PRINT CHR$(7) used t sound a BEEP in QuickBasic and older QB64 versions, but not any longer. I wonder who the dev was who decided to get the BEEP out of QB64?

Pete
Reply
#2
Doesn't always work. I've completely given up on it and pretend it doesn't exist.
Reply
#3
And it's a bitch to format, too. Finally got that table to show properly.

Seriously, is it inconsistent on Linux for the code as posted? I've never had any problems with it. It should return this...


Attached Files Image(s)
   
Reply
#4
It was a long time ago I tried to use this keyword on Windows. Haven't even tried on Linux because, as I've already said, I've given up on it. I wish I could offer something far more useful than that. BTW shocked that you put a screenshot of Firefox, I was almost fooled it was Edge or some other browser. :O Prefer that look over the child's play I have on my side.

But it's also because I'm using AppImage "Nightly" build.

EDIT: In order to see the whole screenshot, with the context menu at the top-right, have to zoom to 80%. (facepalm)
Reply
#5
_CONTROLCHR works just fine -- whether that's on Windows, Linux, or Mac.  

IF there's a problem with it, it's with how people interact with the FUNCTION and the SUB versions of the two.

Code: (Select All)
_ControlChr Off
For i = 0 To 32
    Print Chr$(i);
Next
Print

If _ControlChr Then
    For i = 0 To 32
        Print Chr$(i);
    Next
    Print ; "It's ON.  Right??"
Else
    Print "Nope.  It's off"
End If


Run the above and you'll quickly see what can toss most folks for a loop.

_CONTROLCHR, as a sub, you toggle OFF to print the extended ASCII characters, toggle ON to... basically do nothing anymore.  OpenGL doesn't have the same support for the control characters that the old SDL version did -- thus why Pete remembers CHR$(7) as BEEP, but it doesn't do so anymore.

_CONTROLCHR, as a function, is basically reversed.  ON, it says you're printing those extended ASCII characters.  OFF, you're basically doing nothing.

How the values got inverted between the two, I dunno, but it's been that way forever, and swapping them would break a lot of user's existing code, so we're stuck living with what we have.

Turn it OFF via the SUB, and the FUNCTION will tell you you're ON for printing to the screen.
Turn it ON via the SUB, and the FUNCTION will tell you you're OFF for printing to the screen.

I suppose a better name for the function would be something like _CONTROLCHRDISPLAY...  But who wants all that extra typing?  Tongue



Honestly, since _CONTROLCHR ON doesn't do *anything* anymore -- no BEEP, backspace, enter, ect, ect -- I'm of the opinion that we should just obsolete the two commands, make _CONTROLCHR OFF the default and unchangeable setting, and leave it at that.  

Why offer an option that basically does nothing?

Either someday, we need to reimplement those control actions to the keys, or else we need to seriously rethink a toggle which switches between "do something" and "do squat".  At least, that's my personal opinion on the situation as it currently exists.  Tongue
Reply
#6
interesting keyword and thanks for the much needed chime in, Steve
Reply




Users browsing this thread: 2 Guest(s)