Solved

Progress Bar

Posted on 2003-12-06
10
651 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now