在vb程序执行时,怎么设置一个按钮,使程序运行先暂停,然后在单击该按钮后,又能够继续执行呢?求助各位高手,请指点!

解决方案 »

  1.   

    简单的办法如下试试:
    Option ExplicitPrivate Sub Command1_Click()
        Dim i
        For i = 1 To 1000
            DoEvents
            Debug.Print i
        Next i
    End SubPrivate Sub Command2_Click()
        MsgBox "stop"
    End Sub单击Command2程序暂停
      

  2.   

    是不是这个意思?试试:
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Dim SUM As Long, BEPAUSE As Boolean
    Private Sub Command1_Click()
    If BEPAUSE = True Then BEPAUSE = False: Command1.Caption = "PAUSE": GETN
    If BEPAUSE = False Then Command1.Caption = "RESTART": BEPAUSE = True
    End Sub
    Sub GETN()
    Do While BEPAUSE = False
    Sleep 200
    DoEvents
    SUM = SUM + 1
    Me.Caption = SUM
    Loop
    End Sub
    Private Sub Form_Load()
    Command1.Caption = "START"
    BEPAUSE = True
    End Sub
      

  3.   

    Option Explicit
    Dim WaitFlag As Boolean
    Private Sub Command1_Click()
        Dim i As Long
        For i = 1 To 100000
            DoEvents
            If WaitFlag = True Then
                Do While WaitFlag = True
                    DoEvents
                Loop
            End If
            Me.Caption = CStr(i)
        Next
    End SubPrivate Sub Command2_Click()
    WaitFlag = Not WaitFlag
    End SubPrivate Sub Form_Load()
        WaitFlag = False
    End Sub