数据备份进度条老提示错误,请大家帮忙看看。。。
Option Explicit
Private Sub Command1_Click()
a = MsgBox("确定备份数据?", 4, "明日图书")
If a = vbYes Then
Command1.Enabled = False
ProgressBar.Visible = True
ProgressBar.Max = UBound(workarea)
ProgressBar.Value = ProgressBar.Min
For counter = LBound(workarea) To UBound(workarea)
workarea(counter) = " initial value" & counter
ProgressBar.Value = counter
Open str1 For Binary As #1
Open str2 For Binary As #2
Do While Not EOF(1)
Get #1, , Char
Put #2, , Char
Loop
Close
Next counter
ProgressBar.Value = ProgressBar.Min
MsgBox "数据备份成功!", , "明日图书"
Command1.Enabled = True
End If
End Sub
Private Sub Form_Load()
str1 = App.Path & "\1.txt"
str2 = App.Path & "\beifen\2.txt"
End Sub
[解决办法]
没必要循环和显示进度吧?
Private Sub Command1_Click()
Dim Char() As Byte
a = MsgBox("确定备份数据?", 4, "明日图书")
If a = vbYes Then
Command1.Enabled = False
Open str1 For Binary As #1
Open str2 For Binary As #2
Redim Char(LOF(1)) '将 Get 的长度与文件 1 取齐
Get #1, , Char
Put #2, , Char
Close #2
Close #1
MsgBox "数据备份成功!", , "明日图书"
Command1.Enabled = True
End If
End Sub