Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 26th, 2003, 10:37 AM
linh linh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 245 linh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 27 sec
Reputation Power: 6
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

Reply With Quote
  #2  
Old November 27th, 2003, 06:31 AM
fnotti fnotti is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Argentina
Posts: 10 fnotti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #3  
Old November 27th, 2003, 09:20 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > the window did not close while the files are copying


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway