|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
the window did not close while the files are copying
Visual Basic 5.0
form1 called form2. Form2 two then performs file copying. Everything copy. The problem is while it copy, if I click on the button Quit (stop copying), Form2 do not close but continue to copy files. The code below is what is in Form2. Notice on the line with a label 99 and 100. 99 Unload Form_Copy_Status I did tell the form to unload, but it won 't. It continue to copy files. 100 End If it put this line in, it will quit the whole application. I just want to close Form2 so that the file will stop copying. I do not want to close the whole application. ================================== Code:
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_Directory As String 'C:\winnt\system32\'
Private Sub Form_Load()
Call Compute_Total_Files_Size
End Sub
Private Sub Compute_Total_Files_Size()
On Error GoTo ErrorHandler
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
Dim A As String
A = "C:\WebOffice_VPN\"
'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.GetFolder(Source_File_Path_1)
Error_Exist = False
Folder_Size = object_Folder.Size
Total_Percentage_Completed = 0
Form_Copy_Status.Show
ProgressBar2.Max = 100 'Set it to 100%
ProgressBar2.Visible = True 'Make the ProgressBar2 visible
Timer2.Interval = 1000 '1000 is equal to 1 second
Timer2.Enabled = True 'Start the Timer2
For Each object_File In object_Folder.Files
Form_Copy_Status.Copy_From = Source_File_Path_1 & object_File.Name 'A:\WebOffice_VPN\
Form_Copy_Status.Copy_To = Form1.Directory_Box & object_File.Name 'C:\WebOffice_VPN\
object_FileSystem.CopyFile Source_File_Path_1 & object_File.Name, "C:\WebOffice_VPN\"
'object_FileSystem.CopyFile Source_File_Path_1 & object_File.Name, Directory_Box
Percent_Of_Total = Val(Format((object_File.Size / Folder_Size) * 100, "0.00"))
Total_Percentage_Completed = Val(Format(Total_Percentage_Completed + Percent_Of_Total, "0.00"))
Total_Percentage_Done.Text = Val(Format(Total_Percentage_Completed, "0.00"))
DoEvents
Next object_File
End Sub
Private Sub Timer2_Timer()
Static integer_Time
If IsEmpty(integer_Time) Then
integer_Time = 1
Time_Text_Box = integer_Time
End If
'Total_Percentage_Done is the percentage of the total number of bytes
'of all files that was copied. This number is always from 0 to 100
ProgressBar2.Value = Total_Percentage_Done.Text
If ProgressBar2.Value = ProgressBar2.Max Then
Timer1.Enabled = False
ProgressBar2.Visible = False
Time_Text_Box = integer_Time
ProgressBar2.Value = ProgressBar2.Min
Else
integer_Time = integer_Time + 1
Time_Text_Box = integer_Time
End If
End Sub
Private Sub Quit_Click()
Dim Msg, Style, Title, Response, MyString
Msg = "Do you want to stop installing the program ?" ' Define message.
Style = vbYesNo + vbInformation + vbDefaultButton2 ' Define buttons.
Title = "MsgBox Stop installing the program" ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Timer2.Enabled = False
99 Unload Form_Copy_Status
100 End
End If
End Sub
|
|
#2
|
|||
|
|||
|
bFlag2Quit
May be you can use a flag Boolean Variable to force exit for.
b=false For each ..... if b then exit for endif copyFiles doevents next if b then unload me endif on cmdQuit_click() b=true end sub Bye ![]() |
|
#3
|
|||
|
|||
|
U can do it as this way:
1.set a global variable "stopflag" as boolean type,and initialize this variable's value to false 2.add this code in the Compute_Total_Files_Size function : For Each object_File In object_Folder.Files Form_Copy_Status.Copy_From = Source_File_Path_1 & object_File.Name 'A:\WebOffice_VPN\ Form_Copy_Status.Copy_To = Form1.Directory_Box & object_File.Name 'C:\WebOffice_VPN\ object_FileSystem.CopyFile Source_File_Path_1 & object_File.Name, "C:\WebOffice_VPN\" 'object_FileSystem.CopyFile Source_File_Path_1 & object_File.Name, Directory_Box Percent_Of_Total = Val(Format((object_File.Size / Folder_Size) * 100, "0.00")) Total_Percentage_Completed = Val(Format(Total_Percentage_Completed + Percent_Of_Total, "0.00")) Total_Percentage_Done.Text = Val(Format(Total_Percentage_Completed, "0.00")) DoEvents if stopflag=false then unload me Next object_File 3.add this code: Private Sub Quit_Click() Dim Msg, Style, Title, Response, MyString Msg = "Do you want to stop installing the program ?" ' Define message. Style = vbYesNo + vbInformation + vbDefaultButton2 ' Define buttons. Title = "MsgBox Stop installing the program" ' Define title. Response = MsgBox(Msg, Style, Title) If Response = vbYes Then istopflag=true end if End Sub |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > the window did not close while the files are copying |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|