Vb Loop Pause Until User Clicks Continue
-
Jul 29th, 2005,09:14 AM #1
Thread Starter
New Member
[RESOLVED] Pause until button clicked?
I have a frame that has an "OK" and "Cancel" button on it. After I display the frame, I want to prevent the next line of code from executing until they click one of the two buttons. How do I put some kind of pause in my code that will wait until they click a button?
-
Jul 29th, 2005,09:26 AM #2
Re: Pause until button clicked?
By setting a boolean flag
VB Code:
-
Dim blnFlag As Boolean
-
Private Sub Command1_Click()
-
blnFlag = True
-
End Sub
-
Private Sub Form_Load()
-
Me.Show
-
MsgBox "First MessageBox!"
-
Do Until blnFlag
-
DoEvents
-
Loop
-
MsgBox "Second MessageBox!"
-
End Sub
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
-
Jul 29th, 2005,09:27 AM #3
Re: Pause until button clicked?
if you're not looping or runing any timers then nothing will get excuted untill user does something. In any case here is an API function that you can utilize:
VB Code:
-
Option Explicit
-
Private Declare Function SleepEx Lib "kernel32" _
-
(ByVal dwMilliseconds As Long, ByVal bAlertable As Long) As Long
-
Private Sub Command1_Click()
-
SleepEx 5000, False 'pause execution for 5 seconds
-
End Sub
-
-
Jul 29th, 2005,09:37 AM #4
Thread Starter
New Member
Re: Pause until button clicked?
Thanks dudes!
I tried exactly what Chemical Nova was talking about, except I didn't have the DoEvents in the loop.
vbforums rocks
-
Jul 29th, 2005,09:42 AM #5
Re: [RESOLVED] Pause until button clicked?
i liked chemicalNova ways better
-
Jul 29th, 2005,09:48 AM #6
Re: Pause until button clicked?
Originally Posted by helpmewithvb
-
Jul 29th, 2005,10:05 AM #7
Re: [RESOLVED] Pause until button clicked?
Which is true. So taking into account RhinoBull's post:
VB Code:
-
Dim blnFlag As Boolean
-
Dim counter As Byte
-
Private Sub Command1_Click()
-
blnFlag = True
-
End Sub
-
Private Sub Form_Load()
-
Me.Show
-
MsgBox "First MessageBox!"
-
Do Until blnFlag
-
If (counter < 255) Then
-
counter = counter + 1
-
Else
-
counter = 0
-
DoEvents
-
End If
-
Loop
-
MsgBox "Second MessageBox!"
-
End Sub
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
-
Jul 29th, 2005,12:55 PM #8
Thread Starter
New Member
Re: [RESOLVED] Pause until button clicked?
Use it with caution (perhaps every 100 or so iterations) - otherwise it may take over your cpu ...
-
Jul 29th, 2005,01:04 PM #9
Re: [RESOLVED] Pause until button clicked?
-
Jul 29th, 2005,01:09 PM #10
Re: [RESOLVED] Pause until button clicked?
Use it with caution (perhaps every 100 or so iterations) - otherwise it may take over your cpu ...
Good advise. Can someone please elaborate on this? How does it take over the CPU?
Well around 100 + iterations you cpu %s will start going up shokingly!!
after 100 might b even 150 you processor resources will mostly b consitrated on your application.@@@@@@@@@@@@@@@@@@@@@@@
over use of cpu might cuss the computer to crash or even loss of data
@@@@@@@@@@@@@@@@@@@@@@@
-
Jul 29th, 2005,01:14 PM #11
Re: [RESOLVED] Pause until button clicked?
What the heck are you talking about?
If you have a long loop then once in awhile you have to pass control to OS or otherwise your app will freeze pretty much everything on your pc. To do that VB6 doesn't have much to offer except for DoEvents which in turn will charge your CPU upto 100% if not used wisely - using iterations is the only way arround, though.
Source: https://www.vbforums.com/showthread.php?352247-RESOLVED-Pause-until-button-clicked
0 Response to "Vb Loop Pause Until User Clicks Continue"
Post a Comment