Solved

Progress Bar

Posted on 2003-12-06
10
657 Views
Last Modified: 2010-05-03
I made a program to backup certain directories and files. And when you browse to a directory/file and select one it adds it to list boxes.

Now when I click Start I want it to start a progress bar of it copying the files from one directory to the other. Does anyone know how I can do this? Code examples would be appreciated.
0
Comment
Question by:Jmjl3
  • 5
  • 5
10 Comments
 
LVL 14

Expert Comment

by:aelatik
ID: 9888928
First of all you need to know the filecount before you start the progress. After that its very easy.

These are the parameters you need to set before progress.

Progressbar1.min = 0
Progressbar1.max = FILECOUNT
Progressbar1.value = 0

After that in your filecopy loop you increase the value each time you copy a file like :

Progressbar1.value = Progressbar1.value + 1
0
 

Author Comment

by:Jmjl3
ID: 9888951
I assume by Filecount, I need to know how many files there are? I am using listboxes...1 listbox for files, and a second for directories. So I won't know how many files there are in the directories because some folders are bigger...
0
 
LVL 14

Expert Comment

by:aelatik
ID: 9889005
Post the code of what you have so far and ill implement the progressbar for you.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Jmjl3
ID: 9889417
Private Sub Command1_Click()
CommonDialog1.ShowOpen
Text1.Text = CommonDialog1.FileName
End Sub

Private Sub Command2_Click()
If Text1.Text = "" Then
MsgBox "You must enter a file to backup before you add it to the list.", vbExclamation, "Add file error"
Else
List1.AddItem (Text1.Text)
End If
End Sub

Private Sub Command5_Click()
End
End Sub

Private Sub Command6_Click()
If Text3.Text = "" Then
MkDir "C:\Bck1"
Else
MkDir "C:\" & Text3.Text
End If
End Sub

Private Sub Timer1_Timer()
If Text3.Text = "" Then
Label15.Caption = "Bck1"
Else
Label15.Caption = Text3.Text
End If
End Sub


In command6_click that is the START button. And also in that sub is it possible to have it go find a files that are listed in a listbox and copy them to a directory? I would appreciate it.
0
 
LVL 14

Accepted Solution

by:
aelatik earned 140 total points
ID: 9889622
This would be your command6 sub with copy and progressbar functionality :

Private Sub Command6_Click()
    Dim DIR_TO_COPY As String
    If Text3.Text = "" Then
        MkDir "C:\Bck1"
        DIR_TO_COPY = "c:\Bck1"
    Else
        MkDir "C:\" & Text3.Text
        DIR_TO_COPY = "c:\" & Text3.Text
    End If
    If List1.ListCount > 0 Then
        ProgressBar1.Min = 0
        ProgressBar1.Max = List1.ListCount
        ProgressBar1.Value = 0
        Dim LOOPER As Long
        Dim FNAME As String
        For LOOPER = 0 To List1.ListCount - 1
            FNAME = Right(List1.List(LOOPER), InStr(1, StrReverse(List1.List(LOOPER)), "\") - 1)
            FileCopy List1.List(i), DIR_TO_COPY & "\" & FNAME
            ProgressBar1.Value = ProgressBar1.Value + 1
            DoEvents
        Next
    End If
End Sub
0
 

Author Comment

by:Jmjl3
ID: 9891058
Perfect!
2 more simple questions, I hope. And I increased the points to 140...It's all I have.

Can the CommonDialog control select directories? Because as far as I know it only selects files.

2) I have a second listbox, list2. In that directory it displays the directory paths. Is it also possible to backup directories into that folder? Your help is GREATLY appreciated!
0
 
LVL 14

Expert Comment

by:aelatik
ID: 9891687
1) No, you can do this with the DRIVE and DIR control instead. Add the Drive control and the DIR control to your form and use the following code :

Private Sub Dir1_Change()
    Text1.Text = Dir1.Path
End Sub

Private Sub Drive1_Change()
    Drive1.Drive = Dir1.Path
End Sub
0
 
LVL 14

Expert Comment

by:aelatik
ID: 9891688
2) you can use the same filecopy method in there to
0
 

Author Comment

by:Jmjl3
ID: 9892050
Hmmm, I tried doing it for the directories, but I can't seem to get it right...
0
 

Author Comment

by:Jmjl3
ID: 9916814
...Anyone???
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question