我在vb中对access数据库进行压缩和备份时,时间比较长,于是我就加了个类似进度条的东西(一个图片在进度条里左右循环移动),但是程序运行时,进度条里的图片就不动了,可能是要加个Doevents,但不知道加到哪?加了几个地方都不行。
进度条里的图片移动是用timer控件控制的,按理说应该不影响的,这个怎么解决,压缩备份的代码:
Public Sub CompactJetDatabase(Location As String, Optional BackupOriginal As Boolean = True)
'工程中引用Microsoft DAO 3.6 Object Library'On Error GoTo CompactErrDim strBackupFile As StringDim strTempFile As String'检查数据库文件是否存在If Len(Dir(Location)) Then'如果需要备份就执行备份If BackupOriginal = True ThenstrBackupFile = App.Path & "\backup.mdb"If Len(Dir(strBackupFile)) Then Kill strBackupFileFileCopy Location, strBackupFile
End If'创建临时文件名strTempFile = App.Path & "\temp.mdb"If Len(Dir(strTempFile)) Then Kill strTempFile'通过DBEngine压缩数据库文件DBEngine.CompactDatabase Location, strTempFile'删除原来的数据库文件
Kill Location'拷贝刚刚压缩过临时数据库文件至原来位置FileCopy strTempFile, Location
'删除临时文件Kill strTempFileElseEnd If'CompactErr:'Exit SubEnd Sub
滚动条代码:
’p1是个图片框
Private Sub Timer1_Timer()
p1.Left = p1.Left + 70
If p1.Left > xp1.Left + xp1.Width - p1.Width - 20 Then'p1.Left = xp1.Left
Timer2.Enabled = True
Timer1.Enabled = False
End If
End SubPrivate Sub Timer2_Timer()p1.Left = p1.Left - 70
If p1.Left < xp1.Left + 20 ThenTimer1.Enabled = True
Timer2.Enabled = FalseEnd If
End Sub
进度条里的图片移动是用timer控件控制的,按理说应该不影响的,这个怎么解决,压缩备份的代码:
Public Sub CompactJetDatabase(Location As String, Optional BackupOriginal As Boolean = True)
'工程中引用Microsoft DAO 3.6 Object Library'On Error GoTo CompactErrDim strBackupFile As StringDim strTempFile As String'检查数据库文件是否存在If Len(Dir(Location)) Then'如果需要备份就执行备份If BackupOriginal = True ThenstrBackupFile = App.Path & "\backup.mdb"If Len(Dir(strBackupFile)) Then Kill strBackupFileFileCopy Location, strBackupFile
End If'创建临时文件名strTempFile = App.Path & "\temp.mdb"If Len(Dir(strTempFile)) Then Kill strTempFile'通过DBEngine压缩数据库文件DBEngine.CompactDatabase Location, strTempFile'删除原来的数据库文件
Kill Location'拷贝刚刚压缩过临时数据库文件至原来位置FileCopy strTempFile, Location
'删除临时文件Kill strTempFileElseEnd If'CompactErr:'Exit SubEnd Sub
滚动条代码:
’p1是个图片框
Private Sub Timer1_Timer()
p1.Left = p1.Left + 70
If p1.Left > xp1.Left + xp1.Width - p1.Width - 20 Then'p1.Left = xp1.Left
Timer2.Enabled = True
Timer1.Enabled = False
End If
End SubPrivate Sub Timer2_Timer()p1.Left = p1.Left - 70
If p1.Left < xp1.Left + 20 ThenTimer1.Enabled = True
Timer2.Enabled = FalseEnd If
End Sub
用jro.JetEngine,好像如果备份一次,下次名字一样的话,好像不能覆盖吧?
你百度一下:GIF 进度条 有一堆,很好用。
FileCopy Location, strBackupFileDBEngine.CompactDatabase Location, strTempFile