Solved

Progress Bar

Posted on 2003-12-06
10
656 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

777 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