|
-
Feb 6th, 2005, 11:31 PM
#1
Thread Starter
Hyperactive Member
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
-
Feb 6th, 2005, 11:32 PM
#2
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.
-
Feb 6th, 2005, 11:35 PM
#3
Thread Starter
Hyperactive Member
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
-
Feb 6th, 2005, 11:36 PM
#4
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:
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
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Feb 6th, 2005, 11:40 PM
#5
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.
-
Feb 6th, 2005, 11:40 PM
#6
Re: progress bar
There is a very nice sample by Randy Birch .
-
Feb 6th, 2005, 11:41 PM
#7
Thread Starter
Hyperactive Member
Re: progress bar
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)
-
Feb 6th, 2005, 11:47 PM
#8
Re: progress bar
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.
Last edited by dglienna; Feb 7th, 2005 at 12:03 AM.
-
Feb 6th, 2005, 11:49 PM
#9
Thread Starter
Hyperactive Member
Re: progress bar
ProgressBar1.Max = 0 - invalid property value?
-
Feb 6th, 2005, 11:57 PM
#10
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.
-
Feb 6th, 2005, 11:59 PM
#11
Thread Starter
Hyperactive Member
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
-
Feb 7th, 2005, 12:02 AM
#12
Re: progress bar
just take that line out. I set it again when you set nCount to the number of files to load.
-
Feb 7th, 2005, 12:05 AM
#13
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:
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
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Feb 7th, 2005, 12:58 AM
#14
Re: progress bar
VB Code:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|