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
Printable View
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
No, once you know the size, set the progress bar maximum, and as you transfer packets, update the progress every set number of packets.
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
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:
Private Sub Command1_Click Dim i As Integer Progressbar1.Min = 0 Progressbar1.Max = 100 Progressbar1.Value = 0 Progressbar1.Scrolling = ccScrollingSmooth For i = 1 to 100 'Do your filecopy or what ever for a single file Progressbar1.Value = i DoEvents Next End Sub
I would update the progress bar after each file is done. if there is 10 of them, then use 10% for each step.
There is a very nice sample by Randy Birch .
Is it in here where I would need to add it
VB Code:
Private Sub Command1_Click() Dim strFile() As String, strPath As String Dim n As Long, nCount As Long On Error Resume Next With CommonDialog1 .Flags = cdlOFNAllowMultiselect + cdlOFNExplorer .CancelError = True .InitDir = "C:\" .DialogTitle = "Select File To Add To Playlist" .ShowOpen If Err.Number <> cdlCancel Then strFile = Split(.FileName, vbNullChar) nCount = UBound(strFile) If nCount = 0 Then 'Only one file is selected so split up the path and the filename ReDim strFile(1) strFile(0) = Left$(.FileName, InStrRev(.FileName, "\")) strFile(1) = Mid$(.FileName, InStrRev(.FileName, "\") + 1) nCount = 1 End If strPath = strFile(0) If Right$(strPath, 1) <> "\" Then strPath = strPath & "\" End If For n = 1 To nCount If Len(Dir(FAVORITES_FOLDER & strFile(n))) = 0 Then FileCopy strPath & strFile(n), FAVORITES_FOLDER & strFile(n) End If Next End If End With End Sub
Thanks (I learn more here than college lol)
VB Code:
Private Sub Command1_Click() Progressbar1.Min = 0 Progressbar1.Value = 0 Progressbar1.Scrolling = ccScrollingSmooth Dim strFile() As String, strPath As String Dim n As Long, nCount As Long On Error Resume Next With CommonDialog1 .Flags = cdlOFNAllowMultiselect + cdlOFNExplorer .CancelError = True .InitDir = "C:\" .DialogTitle = "Select File To Add To Playlist" .ShowOpen If Err.Number <> cdlCancel Then strFile = Split(.FileName, vbNullChar) nCount = UBound(strFile) If nCount = 0 Then 'Only one file is selected so split up the path and the filename ReDim strFile(1) strFile(0) = Left$(.FileName, InStrRev(.FileName, "\")) strFile(1) = Mid$(.FileName, InStrRev(.FileName, "\") + 1) nCount = 1 End If strPath = strFile(0) If Right$(strPath, 1) <> "\" Then strPath = strPath & "\" End If Progressbar1.Max = nCount For n = 1 To nCount If Len(Dir(FAVORITES_FOLDER & strFile(n))) = 0 Then FileCopy strPath & strFile(n), FAVORITES_FOLDER & strFile(n) End If Progressbar1.Value = nCount Next End If End With End Sub
I think this will do it. I'm not sure that you can do it much better.
ProgressBar1.Max = 0 - invalid property value?
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.
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
just take that line out. I set it again when you set nCount to the number of files to load.
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.
HTHVB Code:
Option Explicit 'Add a progressbar 'Add a commondialog box control 'Add a command button Private Type SHFILEOPSTRUCT hWnd As Long wFunc As Long pFrom As String pTo As String fFlags As Integer fAborted As Boolean hNameMaps As Long sProgress As String End Type Private Const FO_DELETE = &H3 Private Const FOF_ALLOWUNDO = &H40 Private Const FOF_SIMPLEPROGRESS As Long = &H100 Private Const FO_COPY As Long = &H2 Private Const FO_MOVE As Long = &H1 Private Const FO_RENAME As Long = &H4 Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long Private Sub Command1_Click() Dim SHFileOp As SHFILEOPSTRUCT CommonDialog1.DialogTitle = "Select a file to copy ..." CommonDialog1.Filter = "All Files (*.*)|*.*" CommonDialog1.ShowOpen With SHFileOp .wFunc = FO_COPY .pFrom = CommonDialog1.FileName .pTo = "C:\Test.txt" 'You can also rename the file if you want of leave it the same .fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS End With 'perform file operation SHFileOperation SHFileOp MsgBox "The file '" + CommonDialog1.FileName + "' has been copied to your C drive!", vbInformation + vbOKOnly, App.Title ' End Sub
VB Code:
progress1.visible = false