Results 1 to 14 of 14

Thread: progress bar

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    progress bar

    Hi all
    I have an app that transfers files from one location to the other using common dialog is it difficult to add a progress bar to display while the files are bieng transfered

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: progress bar

    No, once you know the size, set the progress bar maximum, and as you transfer packets, update the progress every set number of packets.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: progress bar

    sorry, I misunderstand a bit when you say about the size because the files differ in size. or am I barking up the wrong tre as usual
    thanks

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: progress bar

    No not at all. After you add the PB to your project ('Click Project > Components >
    Controls tab > MS Windows Common Controls 6.0) you can set the values
    preping it rof use in your loop.

    VB Code:
    1. Private Sub Command1_Click
    2.  
    3.     Dim i As Integer
    4.  
    5.     Progressbar1.Min = 0
    6.     Progressbar1.Max = 100
    7.     Progressbar1.Value = 0
    8.     Progressbar1.Scrolling = ccScrollingSmooth
    9.  
    10.     For i = 1 to 100
    11.         'Do your filecopy or what ever for a single file
    12.         Progressbar1.Value = i
    13.         DoEvents
    14.     Next
    15.  
    16. End Sub
    Last edited by RobDog888; Feb 6th, 2005 at 11:55 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: progress bar

    I would update the progress bar after each file is done. if there is 10 of them, then use 10% for each step.

  6. #6

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: progress bar

    Is it in here where I would need to add it


    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim strFile() As String, strPath As String
    3.     Dim n As Long, nCount As Long
    4.     On Error Resume Next
    5.     With CommonDialog1
    6.         .Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
    7.         .CancelError = True
    8.         .InitDir = "C:\"
    9.         .DialogTitle = "Select File To Add To Playlist"
    10.      
    11.         .ShowOpen
    12.         If Err.Number <> cdlCancel Then
    13.             strFile = Split(.FileName, vbNullChar)
    14.             nCount = UBound(strFile)
    15.             If nCount = 0 Then
    16.                 'Only one file is selected so split up the path and the filename
    17.                 ReDim strFile(1)
    18.                 strFile(0) = Left$(.FileName, InStrRev(.FileName, "\"))
    19.                 strFile(1) = Mid$(.FileName, InStrRev(.FileName, "\") + 1)
    20.                 nCount = 1
    21.             End If
    22.             strPath = strFile(0)
    23.             If Right$(strPath, 1) <> "\" Then
    24.                 strPath = strPath & "\"
    25.             End If
    26.             For n = 1 To nCount
    27.                 If Len(Dir(FAVORITES_FOLDER & strFile(n))) = 0 Then
    28.                     FileCopy strPath & strFile(n), FAVORITES_FOLDER & strFile(n)
    29.                 End If
    30.             Next
    31.         End If
    32.     End With
    33. End Sub

    Thanks (I learn more here than college lol)

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: progress bar

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3.     Progressbar1.Min = 0
    4.     Progressbar1.Value = 0
    5.     Progressbar1.Scrolling = ccScrollingSmooth
    6.  
    7.     Dim strFile() As String, strPath As String
    8.     Dim n As Long, nCount As Long
    9.     On Error Resume Next
    10.     With CommonDialog1
    11.         .Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
    12.         .CancelError = True
    13.         .InitDir = "C:\"
    14.         .DialogTitle = "Select File To Add To Playlist"
    15.      
    16.         .ShowOpen
    17.         If Err.Number <> cdlCancel Then
    18.             strFile = Split(.FileName, vbNullChar)
    19.             nCount = UBound(strFile)
    20.             If nCount = 0 Then
    21.                 'Only one file is selected so split up the path and the filename
    22.                 ReDim strFile(1)
    23.                 strFile(0) = Left$(.FileName, InStrRev(.FileName, "\"))
    24.                 strFile(1) = Mid$(.FileName, InStrRev(.FileName, "\") + 1)
    25.                 nCount = 1
    26.             End If
    27.             strPath = strFile(0)
    28.             If Right$(strPath, 1) <> "\" Then
    29.                 strPath = strPath & "\"
    30.             End If
    31.             Progressbar1.Max = nCount
    32.             For n = 1 To nCount
    33.                 If Len(Dir(FAVORITES_FOLDER & strFile(n))) = 0 Then
    34.                     FileCopy strPath & strFile(n), FAVORITES_FOLDER & strFile(n)
    35.                 End If
    36.                 Progressbar1.Value = nCount
    37.             Next
    38.         End If
    39.     End With
    40. End Sub

    I think this will do it. I'm not sure that you can do it much better.
    Last edited by dglienna; Feb 7th, 2005 at 12:03 AM.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: progress bar

    ProgressBar1.Max = 0 - invalid property value?

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: progress bar

    You have to add a progressbar to your project.

    Hit Control-T for Components, and check MS Windows Common Controls 6.0. Then double click on the progress bar control, and move it to where you want it.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: progress bar

    I had one but when it was at 0 for max I got the error I set it to 100 and it worked. Was that right?. Is it difficult to get it not to display when its done.

    thanks

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: progress bar

    just take that line out. I set it again when you set nCount to the number of files to load.

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: progress bar

    I wrote a simpler example for you without using a VB progress bar in your project,
    but rather the Windows standard File Operation progress dialog window.

    No need to determine size of files etc. Its all done by Windows for you.

    VB Code:
    1. Option Explicit
    2. 'Add a progressbar
    3. 'Add a commondialog box control
    4. 'Add a command button
    5. Private Type SHFILEOPSTRUCT
    6.     hWnd As Long
    7.     wFunc As Long
    8.     pFrom As String
    9.     pTo As String
    10.     fFlags As Integer
    11.     fAborted As Boolean
    12.     hNameMaps As Long
    13.     sProgress As String
    14. End Type
    15.  
    16. Private Const FO_DELETE = &H3
    17. Private Const FOF_ALLOWUNDO = &H40
    18. Private Const FOF_SIMPLEPROGRESS As Long = &H100
    19. Private Const FO_COPY As Long = &H2
    20. Private Const FO_MOVE As Long = &H1
    21. Private Const FO_RENAME As Long = &H4
    22.  
    23. Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    24.  
    25. Private Sub Command1_Click()
    26.     Dim SHFileOp As SHFILEOPSTRUCT
    27.    
    28.     CommonDialog1.DialogTitle = "Select a file to copy ..."
    29.     CommonDialog1.Filter = "All Files (*.*)|*.*"
    30.     CommonDialog1.ShowOpen
    31.     With SHFileOp
    32.         .wFunc = FO_COPY
    33.         .pFrom = CommonDialog1.FileName
    34.         .pTo = "C:\Test.txt" 'You can also rename the file if you want of leave it the same
    35.         .fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS
    36.     End With
    37.     'perform file operation
    38.     SHFileOperation SHFileOp
    39.     MsgBox "The file '" + CommonDialog1.FileName + "' has been copied to your C drive!", vbInformation + vbOKOnly, App.Title '
    40.  
    41. End Sub
    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: progress bar

    VB Code:
    1. progress1.visible = false

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width