Make it stop: (ctl + break doesnt work)

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
TropicalET
Newbie
Posts:8
Joined:Thu Jul 19, 2007 12:36 am
Location:Davis, CA
Make it stop: (ctl + break doesnt work)

Post by TropicalET » Fri Sep 28, 2007 12:17 am

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.

Ralph
QBasic God
Posts:134
Joined:Sat Nov 06, 2004 2:27 am
Location:Katy, Texas

Post by Ralph » Sat Sep 29, 2007 2:30 am

Try Control+Break, followed by Esc.
Ralph. Running QuickBASIC Version 4.5, Windows XP Home Edition, Version 2002, Service Pack 2, and HP LaserJet 4L printer.

Mac
Full Member
Posts:48
Joined:Wed Jun 29, 2005 2:01 am
Contact:

Post by Mac » Sun Oct 07, 2007 11:40 pm

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
Mac
The QBasic Forum
http://www.network54.com/Forum/13959

Ralph
QBasic God
Posts:134
Joined:Sat Nov 06, 2004 2:27 am
Location:Katy, Texas

Post by Ralph » Mon Oct 08, 2007 7:11 am

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.
Ralph. Running QuickBASIC Version 4.5, Windows XP Home Edition, Version 2002, Service Pack 2, and HP LaserJet 4L printer.

pebe
Full Member
Posts:33
Joined:Tue Apr 02, 2002 12:19 am
Location:Scotland

Post by pebe » Mon Oct 08, 2007 10:03 am

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

Ralph
QBasic God
Posts:134
Joined:Sat Nov 06, 2004 2:27 am
Location:Katy, Texas

Post by Ralph » Mon Oct 08, 2007 4:59 pm

Sounds much better than Mac's proposal. The Esc key has scan code 15 and ASCII character 27. What is "Key 1"?
Ralph. Running QuickBASIC Version 4.5, Windows XP Home Edition, Version 2002, Service Pack 2, and HP LaserJet 4L printer.

pebe
Full Member
Posts:33
Joined:Tue Apr 02, 2002 12:19 am
Location:Scotland

Post by pebe » Mon Oct 08, 2007 5:28 pm

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

Mac
Full Member
Posts:48
Joined:Wed Jun 29, 2005 2:01 am
Contact:

Post by Mac » Mon Oct 08, 2007 7:26 pm

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
Mac
The QBasic Forum
http://www.network54.com/Forum/13959

pebe
Full Member
Posts:33
Joined:Tue Apr 02, 2002 12:19 am
Location:Scotland

Post by pebe » Sat Oct 13, 2007 9:25 pm

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.

Mac
Full Member
Posts:48
Joined:Wed Jun 29, 2005 2:01 am
Contact:

Post by Mac » Sun Oct 14, 2007 5:42 am

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
Mac
The QBasic Forum
http://www.network54.com/Forum/13959

Post Reply