Page 1 of 1

Make it stop: (ctl + break doesnt work)

Posted: Fri Sep 28, 2007 12:17 am
by TropicalET
Does anyone know an alternative way to make a QB program stop executing, besides control - break? It's not working for me
--running QB 4.5 under dosbox 0.63 and windows 2000.

Posted: Sat Sep 29, 2007 2:30 am
by Ralph
Try Control+Break, followed by Esc.

Posted: Sun Oct 07, 2007 11:40 pm
by Mac
Well, Ralph, looks like we will never know if your suggestion worked.

I was thinking of putting
IF INKEY$ <> "" THEN STOP
in the program at key places.

Mac

Posted: Mon Oct 08, 2007 7:11 am
by Ralph
Right, Mac. I learned some time ago that one should not expect anyone to answer back. If they do, that's great! If they don't, well, I was now expecting them to answer. Seems the last occurs with some frequency, in almost all forums. That's just pwople are, and, we can't live trying to change them. At least, not me!

Your suggestion, Mad, sounds reasonable, but, when one is running a program, and has the problem, that's when we want to be able to stop it. I have had problems of that nature often, and the Ctrl+Break, followed by Esc, has done the trick for me, so, I recommend it as a general method.

Posted: Mon Oct 08, 2007 10:03 am
by pebe
Here’s a snippet. Pressing F1 will generate an interrupt diverting the program to the subroutine ‘trapkey’.

‘put this at the start of your program
ON KEY(1) GOSUB trapkey
KEY(1) ON

‘and this at the end
trapkey:
END

If you want to, you can trap the Escape key instead, but you have to define KEY(15) first. The routine then becomes

KEY 15, CHR$(0) + CHR$(1)
ON KEY (15) GOSUB trapkey
KEY (15) ON

Posted: Mon Oct 08, 2007 4:59 pm
by Ralph
Sounds much better than Mac's proposal. The Esc key has scan code 15 and ASCII character 27. What is "Key 1"?

Posted: Mon Oct 08, 2007 5:28 pm
by pebe
Here is the list:
Key(1) to Key(10) = F1 to F10 function keys
Key (11) Up arrow
Key (12) Left arrow
Key(13) Right arrow
Key(14) Down arrow
Key (15) to Key(25) User defined keys
Key(30) F11 function key
Key(31) F12 function key

For user defined, the two characters are 'shiftcode' and 'keyboard scan code'. Single key presses have shiftcode = 0, so
Escape = 0 + 1
Spacebar = 0 + 57
etc.
There are other shiftcodes for combinations like Shift-Spacebar

Posted: Mon Oct 08, 2007 7:26 pm
by Mac
Ralph wrote:Sounds much better than Mac's proposal.
True. ON KEY effectively inserts
IF INKEY$ = CHR$(27) THEN GOSUB xxx
after EVERY instruction, without the overhead of actually doing that.

Much better if you have no idea why you are stuck.

But usually you know it is in a certain DO-loop and can insert the single IF INKEY$ command right after the DO quite easily without messing with the often-unfamiliar ON KEY stuff.

By the way, I am unable to test the ESC hint because ctrl-break works nicely on WindowsNT. But I will remember it if I am stuck on some other machine. Good info.

Mac

Posted: Sat Oct 13, 2007 9:25 pm
by pebe
It’s not just to get out of a fault condition that requires a quick getout from a program. Several years ago I did a suite of programs in QuickBasic for a company that did electrical maintenance work – mainly for the local council. The company had a receptionist, general and accounts staff and 6 electricians.

The program contained databases for spares and work-in-hand status. The drill was that the receptionist would take jobs over the phone at any time and prioritise them on the database. Each electrician had access to this list of jobs to be done in order of priority. When free, he took the next job and noted in the database that he had done so. That way it was possible for the next man to take the next job with no overlap.

When he had finished he entered details of spares and labour and mark the job as done and ready for invoicing. Accounts staff routinely searched for jobs completed and invoiced them. Nine people all had access to the program and used it for different purposes. That meant that the program was driven by a succession of menus with programs being chained from one to another.

When any user had finished with the program it would have been tedious to backtrack all the way back through the menu and chained programs to the start. It was far easier to do one On KEY instruction in each program that chained back to the main one, ready for the next user.

Posted: Sun Oct 14, 2007 5:42 am
by Mac
Good point.

If the program primarily gets user input via INKEY$ then something like this is good, too:

Code: Select all

DECLARE FUNCTION zkey$ ()
DO
  k$ = zkey
  PRINT k$;
LOOP

FUNCTION zkey$
DO: k$ = INKEY$: LOOP WHILE k$ = ""
IF k$ = CHR$(27) THEN PRINT : SYSTEM
zkey$ = k$
END FUNCTION
Mac