Solved

Progress Bar

Posted on 2003-12-06
10
658 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

733 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