Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Progress Bar

Posted on 2003-12-06
10
Medium Priority
?
663 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 560 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

636 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