lin100
asked on
When the program copy files, the text box Total_Percentage_Done is not being updated
When the program copy files, the text box Total_Percentage_Done is not being updated
It copied all of the files from one directory into another, but the text box showing
percentage completed never got updated.
This line with a 99 mark can be found below
99 Total_Percentage_Done.Text = Total_Percentage_Completed <-- Problem
========================== ========== ========== ========
Option Explicit
'These are public variables and constant within this form and therefore,
'its value can be accessed by any function and procedure eithin this form
Const Source_File_Path_1 = "C:\WINNT\SYSTEM32\" '"A:\WebOffice_VPN\"
Const Source_File_Path_2 = "C:\WINNT\SYSTEM32\" '"A:\WebOffice_VPN\OCX\"
Dim Boot_Up_Drive_Letter As String 'C:\
Dim Boot_Up_Drive_Letter_And_D irectory As String 'C:\winnt\system32\'
////////////////////////// ////////// ////////// ////////// ////////// ////////// /
Private Sub Form_Load()
ProgressBar1.Max = 5
ProgressBar1.Visible = True
'If ProgressBar1.Max = 5, then it will take 5 seconds to fill the Progress Bar
'If ProgressBar1.Max = 10, then it will take 10 seconds to fill the Progress Bar
'If ProgressBar1.Max = 20, then it will take 20 seconds to fill the Progress Bar
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
////////////////////////// ////////// ////////// ////////// ////////// ////////// /
Private Sub timer1_Timer()
Static integer_Time
If IsEmpty(integer_Time) Then
integer_Time = 1
Time_Text_Box = integer_Time
End If
ProgressBar1.Value = integer_Time
If integer_Time = ProgressBar1.Max Then
Timer1.Enabled = False
ProgressBar1.Visible = False
integer_Time = 1
Time_Text_Box = integer_Time
ProgressBar1.Value = ProgressBar1.Min
Call Compute_Total_Files_Size
Else
integer_Time = integer_Time + 1
Time_Text_Box = integer_Time
End If
End Sub
////////////////////////// ////////// ////////// ////////// ////////// ////////// /
Private Sub Compute_Total_Files_Size()
Dim File_Size As Double
Dim Folder_Size As Double
Dim Percent_Of_Total As Double
Dim Total_Percentage_Completed As Double
Dim Error_Exist As Boolean
'Declare File System Variables
Dim object_File As Scripting.File
Dim object_FileSystem As Scripting.FileSystemObject
Dim object_Folder As Scripting.Folder
'Source_File_Path_1 = "A:\WebOffice_VPN\"
'Source_File_Path_2 = "A:\WebOffice_VPN\OCX\"
Set object_FileSystem = New Scripting.FileSystemObject
Set object_Folder = object_FileSystem.GetFolde r(Source_F ile_Path_1 )
Error_Exist = False
Folder_Size = object_Folder.Size
Total_Percentage_Completed = 0
Form_Copy_Status.Show
For Each object_File In object_Folder.Files
Form_Copy_Status.Copy_From = Source_File_Path_1 'A:\WebOffice_VPN\
Form_Copy_Status.Copy_To = Form1.Directory_Box 'C:\WebOffice_VPN\
object_FileSystem.CopyFile Source_File_Path_1 & _
object_File.Name, "C:\WebOffice_VPN\"
Percent_Of_Total = Val(Format((object_File.Si ze / Folder_Size) * 100, "0.00"))
Total_Percentage_Completed = Total_Percentage_Completed + Percent_Of_Total
99 Total_Percentage_Done.Text = Total_Percentage_Completed <-- Problem
Debug.Print " File Name = "; object_File.Name; " File Size = "; _
object_File.Size; "Percent_Of_Total = "; Percent_Of_Total
Next object_File
End Sub
It copied all of the files from one directory into another, but the text box showing
percentage completed never got updated.
This line with a 99 mark can be found below
99 Total_Percentage_Done.Text
==========================
Option Explicit
'These are public variables and constant within this form and therefore,
'its value can be accessed by any function and procedure eithin this form
Const Source_File_Path_1 = "C:\WINNT\SYSTEM32\" '"A:\WebOffice_VPN\"
Const Source_File_Path_2 = "C:\WINNT\SYSTEM32\" '"A:\WebOffice_VPN\OCX\"
Dim Boot_Up_Drive_Letter As String 'C:\
Dim Boot_Up_Drive_Letter_And_D
//////////////////////////
Private Sub Form_Load()
ProgressBar1.Max = 5
ProgressBar1.Visible = True
'If ProgressBar1.Max = 5, then it will take 5 seconds to fill the Progress Bar
'If ProgressBar1.Max = 10, then it will take 10 seconds to fill the Progress Bar
'If ProgressBar1.Max = 20, then it will take 20 seconds to fill the Progress Bar
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
//////////////////////////
Private Sub timer1_Timer()
Static integer_Time
If IsEmpty(integer_Time) Then
integer_Time = 1
Time_Text_Box = integer_Time
End If
ProgressBar1.Value = integer_Time
If integer_Time = ProgressBar1.Max Then
Timer1.Enabled = False
ProgressBar1.Visible = False
integer_Time = 1
Time_Text_Box = integer_Time
ProgressBar1.Value = ProgressBar1.Min
Call Compute_Total_Files_Size
Else
integer_Time = integer_Time + 1
Time_Text_Box = integer_Time
End If
End Sub
//////////////////////////
Private Sub Compute_Total_Files_Size()
Dim File_Size As Double
Dim Folder_Size As Double
Dim Percent_Of_Total As Double
Dim Total_Percentage_Completed
Dim Error_Exist As Boolean
'Declare File System Variables
Dim object_File As Scripting.File
Dim object_FileSystem As Scripting.FileSystemObject
Dim object_Folder As Scripting.Folder
'Source_File_Path_1 = "A:\WebOffice_VPN\"
'Source_File_Path_2 = "A:\WebOffice_VPN\OCX\"
Set object_FileSystem = New Scripting.FileSystemObject
Set object_Folder = object_FileSystem.GetFolde
Error_Exist = False
Folder_Size = object_Folder.Size
Total_Percentage_Completed
Form_Copy_Status.Show
For Each object_File In object_Folder.Files
Form_Copy_Status.Copy_From
Form_Copy_Status.Copy_To = Form1.Directory_Box 'C:\WebOffice_VPN\
object_FileSystem.CopyFile
object_File.Name, "C:\WebOffice_VPN\"
Percent_Of_Total = Val(Format((object_File.Si
Total_Percentage_Completed
99 Total_Percentage_Done.Text
Debug.Print " File Name = "; object_File.Name; " File Size = "; _
object_File.Size; "Percent_Of_Total = "; Percent_Of_Total
Next object_File
End Sub
ASKER
Hi vinnyd79. Thank you very much for your answer. Please explain why I need
DoEvents in order for it to work ?
Under what condition would I used DoEvents ?
You got an A. Please respond to my question
DoEvents in order for it to work ?
Under what condition would I used DoEvents ?
You got an A. Please respond to my question
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
DoEvents
Next object_File