Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to coding slidebar duering copy

Status
Not open for further replies.

cmaknp

Programmer
Aug 28, 2002
25
IN
anyone wud like to help me pls

how to coding in slide bar or progress bar
duering copy file.

pls help
 
from API-guide 3.6

Requires Windows NT 4.0 or later; Win9x/ME: Not supported

you can modify the CopyProgressRoutine function to change the value property of a progressbar instead

Code:
'in a form (Form1)
Private Sub Form_Load()
    'KPD-Team 2001
    'URL: [URL unfurl="true"]http://www.allapi.net/[/URL]
    'E-Mail: KPDTeam@Allapi.net
    Dim Ret As Long
    'set the graphics mode to persistent
    Me.AutoRedraw = True
    'print some text
    Me.Print "Click the form to abort the filecopy"
    'show the form
    Me.Show
    'start copying
    Ret = CopyFileEx("c:\verybigfile.ext", "c:\copy.ext", AddressOf CopyProgressRoutine, ByVal 0&, bCancel, COPY_FILE_RESTARTABLE)
    'show some text
    Me.Print "Filecopy completed " + IIf(Ret = 0, "(ERROR/ABORTED)", "successfully")
End Sub
Private Sub Form_Click()
    'cancel filecopy
    bCancel = 1
End Sub
'in a module
Public Const PROGRESS_CANCEL = 1
Public Const PROGRESS_CONTINUE = 0
Public Const PROGRESS_QUIET = 3
Public Const PROGRESS_STOP = 2
Public Const COPY_FILE_FAIL_IF_EXISTS = &H1
Public Const COPY_FILE_RESTARTABLE = &H2
Public Declare Function CopyFileEx Lib "kernel32.dll" Alias "CopyFileExA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal lpProgressRoutine As Long, lpData As Any, ByRef pbCancel As Long, ByVal dwCopyFlags As Long) As Long
Public bCancel As Long
Public Function CopyProgressRoutine(ByVal TotalFileSize As Currency, ByVal TotalBytesTransferred As Currency, ByVal StreamSize As Currency, ByVal StreamBytesTransferred As Currency, ByVal dwStreamNumber As Long, ByVal dwCallbackReason As Long, ByVal hSourceFile As Long, ByVal hDestinationFile As Long, ByVal lpData As Long) As Long
    'adjust the caption
    Form1.Caption = CStr(Int((TotalBytesTransferred * 10000) / (TotalFileSize * 10000) * 100)) + "% complete..."
    'allow user input
    DoEvents
    'continue filecopy
    CopyProgressRoutine = PROGRESS_CONTINUE
End Function
 
Hello..Still My problem is Hanging

I just draw a progress bar on the form, & copying a file from one directory to another direrctory,

but my progressbar is not showing, like blue part of progressbar shows..which is not showing..

wud anyone help pls.
 
Dim bl, rd, gr, ctr As Integer
Dim box As String
Private Sub Command1_Click()
With PBar1
.Left = 2300
.Top = 770
.Width = 6300
End With
On Error GoTo FileError
PBar1.Visible = True
Timer1.Enabled = True
Dim filesystemobject As Object
Set filesystemobject = CreateObject("scripting.filesystemobject")
filesystemobject.copyfile "c:\Trial.TXT", "f:\trial1.txt"
FileError:
Select Case Err.Number
Case 53
MsgBox ("File Not Found")
Case Default
MsgBox Err.Description
End Select
End Sub

Private Sub Command3_Click()
End
End Sub

Private Sub Form_Load()
With Form1
.Top = 2000
.Height = 5000
.Left = 3000
.Width = 9000
.Caption = "Trial Programes"
End With
With Command1
.Left = 6900
.Top = 1400
.Caption = "Copy"
.ToolTipText = "Click Me!!!"
End With
With Command3
.Left = 6900
.Top = 3000
.Caption = "Exit"
.ToolTipText = "Click Me!!! for Exit"
End With
With PBar1
.Left = 300
.Top = 980
.Width = 7000
.Min = 0
.Max = 200
Timer1.Interval = 10
Timer1.Enabled = False
PBar1.Visible = False
End With
Timer1.Interval = 10
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
PBar1.Value = Int(PBar1.Value) + Val(Time())
If PBar1.Value > 190 Then
PBar1.Value = 0
PBar1.Visible = False
Timer1.Enabled = False
Exit Sub
End If
End Sub
 
You did not use the CopyFileEx API I posted!



An alternative would be to use

Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

With this, you can display the standard file copy progress dialog that Windows shows when copying large files.



Another alternative would be to
open the source file in Binary mode using the standard 'Open' statement
'Get' and 'Put' (write) the contents in chunks, updating your progress bar as you go

I've found that this last alternative is the slowest however (unless somebody has some excellent code out there he wants to share)



Cannot think of any other way to show a copy progress right now
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top