CHOP% ===== Simple function to check whether a channel is open or not Usage ===== ok = CHOP%(n) where ok is either 0 => channel is open, or and error number, usually -6 Normally you will know which channels are open as you probably opened them yourself! However, with SBASIC daughter jobs a program may not know: SBASIC daughter interpreter may be opened in one of two ways. 1) You can start a new 3-window console by entering the command SBASIC in a previous console, or 2) by EXecuting an SBASIC program. In the latter case no console channels are open before you actually try to use one. Any I/O command, using inbuilt commands such as PRINT, LIST, or PAUSE, that default to one of the three standard console channels will cause a "ghost" window to appear and the I/O will be directed to that window, which receives the nominal channel number 0. CHOP% can be used to test whether the program you are running is in the first state or in the second, thus making it easy to change program behaviour according to its circumstances. Example ======= You wish to RUN or EXecute an SBASIC program. If the normal console windows are open, then you are ok with that, However, say the default "ghost" window wont do, you need something a bit bigger: 100 IF CHOP%(0) THEN 110 REMark Channel #0 is not open, ie we're running in a "ghost" console 120 ch = FOPEN('con') 130 WINDOW#ch; 200, 200, 20, 20 140 ELSE 150 REMark Probably a standard 3-window console 160 ch = 1 170 END IF 180 CLS#ch 190 FOR i = 1 TO 10: PRINT#ch; "Hello world!" 200 IF CHOP%(#1) THEN 210 PAUSE#ch: QUIT: REMark View before quitting 220 END IF 230 REMark Standard console? We may want to run it again! Program ======= There may be other uses. I cant think of any right now, but since this was originally one of the earliest assembler commands I wrote, there could very well have been some other reason for it.. The specific code is only some 34b plus the name bytes, so provided it is included as part of a toolkit that also uses the channel routines, the overhead is negligable. Program Status ============== V0.02, pjw, 2025 Apr 09 Conditions of use and DISCLAIMER as per Knoware.no
Generated by QuickHTM, 2025 Apr 19