VB 给你的程序提供暂停功能

VERSION 5.00
Begin VB.Form frmMain
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton cmdEnd
      Caption         =   "结束"
      Height          =   375
      Left            =   2880
      TabIndex        =   3
      Top             =   2280
      Width           =   855
   End
   Begin VB.CommandButton cmdRestore
      Caption         =   "恢复"
      Height          =   495
      Left            =   3240
      TabIndex        =   2
      Top             =   960
      Width           =   975
   End
   Begin VB.CommandButton cmdPause
      Caption         =   "暂停"
      Height          =   375
      Left            =   1200
      TabIndex        =   1
      Top             =   1440
      Width           =   1335
   End
   Begin VB.CommandButton cmdStart
      Caption         =   "执行"
      Height          =   495
      Left            =   1320
      TabIndex        =   0
      Top             =   360
      Width           =   1335
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private isPause As Boolean
Private isEnd As Boolean
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub PauseFun()
    Do While isPause
        If isEnd Then
            Unload Me: End
            Exit Sub
        End If
        DoEvents
        Sleep 10
    Loop
End Sub

Private Sub cmdEnd_Click()
    If Not isPause Then
        Unload Me: End
    Else
        isEnd = True
    End If
End Sub

Private Sub cmdPause_Click()
    isPause = True
End Sub

Private Sub cmdRestore_Click()
    isPause = False
End Sub

Private Sub cmdStart_Click()
    Dim i As Long
    For i = 0 To 1000000000
        DoEvents
        If isPause Then
            Call PauseFun
        End If
        Open App.Path & "/text.txt" For Append As #1
        Print #1, i
        Close #1
    Next
End Sub
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值