Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

progresbar i filecopy

[es] :: Visual Basic 6 :: progresbar i filecopy

[ Pregleda: 4351 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

kopca

Član broj: 14307
Poruke: 118
*.160.EUnet.yu



Profil

icon progresbar i filecopy24.09.2004. u 11:56 - pre 238 meseci
Da li postoji jednostavan nacin da se standardan Microsoft-ov progress bar veze preko nekog dogadjaja za proces kopiranja nekog velikog fajla?
progbar.min = 0
progbar.max = filesize
itd...
kopca
 
Odgovor na temu

Shadowed
Vojvodina

Član broj: 649
Poruke: 12851



+4784 Profil

icon Re: progresbar i filecopy24.09.2004. u 12:08 - pre 238 meseci
Nisam siguran na sta mislis pod tim standardan "Microsoft-ov progress bar". Ako mislis na onaj koji prikazuje Windows kada kopiras fajlove moze ali treba malo prekopati po API-u. Ako mislis na onaj koji imas u VB-u moze i preko dogadjaja ali je to cini mi se komplikovaniji nacin.
Ako hoces da kopiras fajl i da prikazujes progres ne mozes to uciniti FileCopy metodom ali mozes tako sto ces "rucno" kopirati fajl. Evo opisa pa ako se ne snadjes videcu i da ti iskodiram (ali me nemoj drzati za rec ;)):
1) podesis progbar.max na recimo 100
2) otvoris fajl koji se kopira (pomocu FSO, objasnjenje u top temi)
3) nadjes velicinu fajla i utvrdis 100-ti deo
4) kreiras novi fajl koji ce biti kopija
5) ucitas 100-ti deo izvornog fajla i upises u novi fajl (ovo mozes da uradis iz vise puta da ne trosis mnogo RAM-a ako je veliki fajl)
6) povecas progbar.value za 1
7) ponovis 5) i 6) do kraja fajla
8) zatvoris source i destination fajlove.
 
Odgovor na temu

mladenovicz
Zeljko Mladenovic
Xoran Technologies, Inc., Ann Arbor, MI,
USA / Software Engineer
Ann Arbor, MI, USA

Član broj: 6598
Poruke: 2065
*.bg.wifi.vline.verat.net

Jabber: mladenovicz@elitesecurity.org
ICQ: 95144142
Sajt: yubc.net/~mz


Profil

icon Re: progresbar i filecopy24.09.2004. u 12:09 - pre 238 meseci
da bi prikazao progress bar moras da kopiras fajl u chunkovima. znaci, otvoris fajl binary i citas chunk po chunk (chunk moze da bude recimo 1024 bajta) i pises chunk u novi fajl. Tako mozes da pratis koliko si podataka prebacio i prikazes progress bar
 
Odgovor na temu

kopca

Član broj: 14307
Poruke: 118
*.151.eunet.yu



Profil

icon Re: progresbar i filecopy24.09.2004. u 12:14 - pre 238 meseci
Moze li malo koda za te chunko-ove posto mi nisu najjasniji... Kako da procitam stoti deo fajla?
kopca
 
Odgovor na temu

mladenovicz
Zeljko Mladenovic
Xoran Technologies, Inc., Ann Arbor, MI,
USA / Software Engineer
Ann Arbor, MI, USA

Član broj: 6598
Poruke: 2065
*.bg.wifi.vline.verat.net

Jabber: mladenovicz@elitesecurity.org
ICQ: 95144142
Sajt: yubc.net/~mz


Profil

icon Re: progresbar i filecopy24.09.2004. u 12:49 - pre 238 meseci
Sa progressbarom iz Windows Explorera

Code:

Private Type SHFILEOPSTRUCT
     hwnd As Long
     wFunc As Long
     pFrom As String
     pTo As String
     fFlags As Integer
     fAnyOperationsAborted As Boolean
     hNameMappings As Long
     lpszProgressTitle As String
End Type
Private Declare Function shFileOperation Lib "shell32.dll" Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) As Long

Private Const FOF_ALLOWUNDO = &H40
'No user interface will be displayed if an error occurs.
Private Const FOF_NOERRORUI = &H400
Private Const FOF_SILENT = &H4      ' don't create progress/report
Private Const FOF_NOCONFIRMATION = &H10        ' Don't prompt the user.
Private Const FOF_FILESONLY As Long = &H80
Private Const FOF_SIMPLEPROGRESS As Long = &H100
Private Const FOF_NOCONFIRMMKDIR As Long = &H200
Private Const FO_MOVE As Long = &H1
Private Const FO_COPY As Long = &H2

' sFrom can be multiple files seperated by vbNullChar
' bFilesOnly: If true only files will be copied or moved if sFrom has wildcards.
' e.g. C:\*.*
Function FileOperation(ByVal sFrom As String, ByVal sTo As String, _
 Optional bMoveFiles As Boolean = False, _
 Optional bShowProgress As Boolean = False, _
 Optional ByVal bPromptUser As Boolean = False, _
 Optional ByVal bFilesOnly As Boolean, _
 Optional ByRef bOperationAborted As Boolean) As Long

    Dim shFileOpt As SHFILEOPSTRUCT
    With shFileOpt

        .hwnd = Me.hwnd
        If bMoveFiles Then
            .wFunc = FO_MOVE
        Else
            .wFunc = FO_COPY
        End If
        .fFlags = FOF_ALLOWUNDO
        If bShowProgress Then .fFlags = .fFlags Or FOF_SIMPLEPROGRESS
        If Not bPromptUser Then .fFlags = .fFlags Or FOF_NOCONFIRMATION Or FOF_NOERRORUI
        If bFilesOnly Then .fFlags = .fFlags Or FOF_FILESONLY
        .pFrom = sFrom & vbNullChar & vbNullChar
        .pTo = sTo & vbNullChar & vbNullChar
    End With

    FileOperation = shFileOperation(shFileOpt)   ' Returns zero if no error
    bOperationAborted = shFileOpt.fAnyOperationsAborted
End Function

 
Odgovor na temu

Shadowed
Vojvodina

Član broj: 649
Poruke: 12851



+4784 Profil

icon Re: progresbar i filecopy25.09.2004. u 16:19 - pre 238 meseci
Ili ako ne volis API ;):
Code:
Private Sub cmdCopy_Click()
    Dim fso As New FileSystemObject
    Dim srcFile As TextStream
    Dim destFile As TextStream
    Dim i As Byte
    Dim ChunkSize As Long
    
    Set srcFile = fso.OpenTextFile(txtSrc.Text)
    Set destFile = fso.CreateTextFile(txtDest.Text, False)
    ChunkSize = Int(FileLen(txtSrc.Text) / 99)
    For i = 1 To 99
        destFile.Write (srcFile.Read(ChunkSize))
        CopyBar.Value = i
        DoEvents
    Next i
    destFile.Write (srcFile.ReadAll)
    CopyBar.Value = 100
    srcFile.Close
    destFile.Close
End Sub

Ovde je potrebno da imas dva TextBox-a (txtSrc i txtDest), jedan CommandButton (cmdCopy) i jedan ProgressBar (CopyBar).
 
Odgovor na temu

[es] :: Visual Basic 6 :: progresbar i filecopy

[ Pregleda: 4351 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.