By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,679 Members | 1,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,679 IT Pros & Developers. It's quick & easy.

Q on event-trapping during build-up of figure

P: n/a
I'm trying to find an equivalent of key-event trapping which is easy in
QBasic. Several of my programs build up a geometric figure with two
parameter line families, eg with two nested for..next loops; after that, the
process is redone, or moves on to a new position of the same figure. With a
slow system each build-up may take some time. But after, say the inner
for...next loop it's easy to scan for a key-event with an a$=inkey$ command
and a trapping-subroutine, so that the build-up may be short-cut.

In VB however I can't find any such quick event trapping procedure. I can
(try to) click any push-buttons I want whilst the figure is built up, it has
to be first completed before the program reacts. I read about a VB program
only responding to events in idle time, which can be "provoked" by some
function like DoEvents(). But nothing seems to work as I expect.

Can anyone suggest some way to achieve "immediate" event-trapping? Otherwise
it would make VB seem rather clumsy with respect to QB :( (-;

Guido
http://www.ping.be/wugi/qbasics.htm

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Wugi" <gu*********@planetinternet.be> wrote in message news:<bs**********@reader08.wxs.nl>...
I'm trying to find an equivalent of key-event trapping which is easy in
QBasic. Several of my programs build up a geometric figure with two
parameter line families, eg with two nested for..next loops; after that, the
process is redone, or moves on to a new position of the same figure. With a
slow system each build-up may take some time. But after, say the inner
for...next loop it's easy to scan for a key-event with an a$=inkey$ command
and a trapping-subroutine, so that the build-up may be short-cut.

In VB however I can't find any such quick event trapping procedure. I can
(try to) click any push-buttons I want whilst the figure is built up, it has
to be first completed before the program reacts. I read about a VB program
only responding to events in idle time, which can be "provoked" by some
function like DoEvents(). But nothing seems to work as I expect.

Can anyone suggest some way to achieve "immediate" event-trapping? Otherwise
it would make VB seem rather clumsy with respect to QB :( (-;

Guido
http://www.ping.be/wugi/qbasics.htm


Put a doevents() cmd in your code, this allows all buttons, etc, to
respond to keypresses, clicks etc.

--Mike
Jul 17 '05 #2

P: n/a
On Fri, 26 Dec 2003 16:47:08 +0100, "Wugi"
<gu*********@planetinternet.be> wrote:
I'm trying to find an equivalent of key-event trapping which is easy in
QBasic. Several of my programs build up a geometric figure with two
parameter line families, eg with two nested for..next loops; after that, the
process is redone, or moves on to a new position of the same figure. With a
slow system each build-up may take some time. But after, say the inner
for...next loop it's easy to scan for a key-event with an a$=inkey$ command
and a trapping-subroutine, so that the build-up may be short-cut.

In VB however I can't find any such quick event trapping procedure. I can
(try to) click any push-buttons I want whilst the figure is built up, it has
to be first completed before the program reacts. I read about a VB program
only responding to events in idle time, which can be "provoked" by some
function like DoEvents(). But nothing seems to work as I expect.

Can anyone suggest some way to achieve "immediate" event-trapping? Otherwise
it would make VB seem rather clumsy with respect to QB :( (-;


The trick with that is to simulate the InKey$

Setting a Form's KeyPreview Property to True
- trapping and remembering any KeyPress
- then using DoEvents and returning and clearing any returned key
Should give you a reasonable simulation of InKey$

Personally I would stick all the Controls on the Form in a Frame, and
disable that, to prevent unwanted Clicks

Jul 17 '05 #3

P: n/a

"Wugi" <gu*********@planetinternet.be> wrote in message
news:bs**********@reader08.wxs.nl...
I'm trying to find an equivalent of key-event trapping which is easy in QBasic. Several of my programs build up a geometric figure with two
parameter line families, eg with two nested for..next loops; after that, the process is redone, or moves on to a new position of the same figure. With a slow system each build-up may take some time. But after, say the inner
for...next loop it's easy to scan for a key-event with an a$=inkey$ command and a trapping-subroutine, so that the build-up may be short-cut.

In VB however I can't find any such quick event trapping procedure. I can (try to) click any push-buttons I want whilst the figure is built up, it has to be first completed before the program reacts. I read about a VB program only responding to events in idle time, which can be "provoked" by some function like DoEvents(). But nothing seems to work as I expect.

Can anyone suggest some way to achieve "immediate" event-trapping? Otherwise it would make VB seem rather clumsy with respect to QB :( (-;

Guido
http://www.ping.be/wugi/qbasics.htm


This sort of thing:

Option Explicit

Private mStop As Boolean

Private Sub Command1_Click()
Dim n As Long
Dim j As Long
Dim x As Double

Command1.Enabled = False
Command2.Enabled = True
mStop = False
DoEvents

For n = 1 To 10000
For j = 1 To n
'do something
x = Sin(j / n)
Next j
DoEvents
If mStop Then
Exit For
End If
Next n

If mStop Then
MsgBox "Command1 cancelled"
Else
MsgBox "Command1 finished"
End If

Command1.Enabled = True
Command2.Enabled = False

End Sub

Private Sub Command2_Click()
mStop = True
End Sub

Jul 17 '05 #4

P: n/a
Wugi :
I'm trying to find an equivalent of key-event trapping which is easy in
QBasic. (...)
Thanks to all repliers!
DoEvents is working fine, not by itself only because it does not branch by
itself (or quit the loop) to, eg, reinitialising the process.
But together with a control flag set at each control event, and unset at
(re-)starting the process, it works fine: "DoEvents" traps the events and
the flag then allows rebranching the process ....

Happy New Year to all!

(bis) Guido
http://www.ping.be/wugi/qbasics.htm


Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.