建立一个ActiveX Exe,加入一个类模块clsCompDB
private Timerid as long
public Event CompactOK()
public sub CompactDB()
set Loder =me
Call SetTimer(0, Timerid, 10, AddressOf TimerProc)
end sub
friend sub CompOK()
raiseevent CompactOK
end sub
加入一个模块
public Loder as clsCompDB
public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public Function TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long) As Long
killtimer 0,timerid
'加入压缩代码
'call loder.CopmOk
set loder=nothing
end sub
再你的程序中引用这个activexexe,withevents创建一个clsCompDB对象,调用CompactDB方法,接收到CompOK事件后压缩结束
Dim backing As Boolean
Private Sub Command1_Click()
Dim i As Long
backing = True '在长时间操作之前,指定backing的值为true
'将doevents语句加入到你的备份语句合适位置,这里我用一个长循环消耗系统时间
For i = 1 To 60000
DoEvents
Debug.Print i
Next
'备份结束后,恢复backing的值为false
backing = False
End Sub
Private Sub Form_Load()
backing = False
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'其他事件类似,即首先判断backing的值,如果backing为false,才继续执行
If backing Then
MsgBox "不要心急"
Cancel = 1
End If
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Form_Load()
Timer1.Interval = 1
End Sub
Private Sub Timer1_Timer()
Static x As Long
Static direction As Boolean
If direction = False Then
Picture1.ForeColor = RGB((255 / Picture1.Width) * x, 0, 255)
x = x + 5
Picture1.Line (x, 0)-(x, Picture1.Height)
If x >= Picture1.Width Then direction = True
Else
Picture1.ForeColor = RGB((255 / Picture1.Width) * x, 255, 0)
x = x - 5
Picture1.Line (x, 0)-(x, Picture1.Height)
If x <= 0 Then direction = False
End If
End Sub