Vb Loop Pause Until User Clicks Continue

  1. #1

    helpmewithvb is offline

    Thread Starter

    New Member


    Resolved [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?


  2. #2

    Re: Pause until button clicked?

    By setting a boolean flag

    VB Code:

                            
    1. Dim blnFlag As Boolean

    2. Private Sub Command1_Click()

    3. blnFlag = True

    4. End Sub

    5. Private Sub Form_Load()

    6. Me.Show

    7. MsgBox "First MessageBox!"

    8. Do Until blnFlag

    9.     DoEvents

    10. Loop

    11. MsgBox "Second MessageBox!"

    12. End Sub

    There may be better ways to do this...but theres a start

    chem


    Visual Studio 6, Visual Studio.NET 2005, MASM


  3. #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:

                          
    1. Option Explicit

    2. Private Declare Function SleepEx Lib "kernel32" _

    3.     (ByVal dwMilliseconds As Long, ByVal bAlertable As Long) As Long

    4. Private Sub Command1_Click()

    5.     SleepEx 5000, False    'pause execution for 5 seconds

    6. End Sub


  4. #4

    helpmewithvb is offline

    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


  5. #5

    Re: [RESOLVED] Pause until button clicked?

    i liked chemicalNova ways better

  6. #6

    Re: Pause until button clicked?

    Quote Originally Posted by helpmewithvb

    , except I didn't have the DoEvents in the loop. ...

    Use it with caution (perhaps every 100 or so iterations) - otherwise it may take over your cpu ...

  7. #7

    Re: [RESOLVED] Pause until button clicked?

    Which is true. So taking into account RhinoBull's post:

    VB Code:

                            
    1. Dim blnFlag As Boolean

    2. Dim counter As Byte

    3. Private Sub Command1_Click()

    4. blnFlag = True

    5. End Sub

    6. Private Sub Form_Load()

    7. Me.Show

    8. MsgBox "First MessageBox!"

    9. Do Until blnFlag

    10.     If (counter < 255) Then

    11.         counter = counter + 1

    12.     Else

    13.         counter = 0

    14.         DoEvents

    15.     End If

    16. Loop

    17. MsgBox "Second MessageBox!"

    18. End Sub

    ...every 255 iterations.

    chem


    Visual Studio 6, Visual Studio.NET 2005, MASM


  8. #8

    helpmewithvb is offline

    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 ...

    Good advise. Can someone please elaborate on this? How does it take over the CPU?

  9. #9

    Re: [RESOLVED] Pause until button clicked?


  10. #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
    @@@@@@@@@@@@@@@@@@@@@@@


  11. #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.

bowmanhibed1980.blogspot.com

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

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel