Visualizzazione dei risultati da 1 a 5 su 5

Discussione: [VB6] Progress Bar

  1. #1
    Utente di HTML.it L'avatar di Fado84
    Registrato dal
    Feb 2004
    Messaggi
    347

    [VB6] Progress Bar

    Salve a tutti, è la prima volta che uso la progress bar e non so proprio come utilizzarla e settarla..
    Scarico delle pagine web con inet e visto che l'operazione è abbastanza lunga vorrei associare a questo "download" la progress bar.. come si fa??
    è possibile anche mettere un label con la % del download??
    grazie mille!!

  2. #2
    ho fatto una classe downloadFile che serve proprio a questo

    codice:
    Option Explicit
    
    '-----------------------------------------------------------------------------
    'Class      : downloadFile
    'Date       : 10/09/2004
    'Author     : Fabio Pileri
    'Purpose    : Download and Save File from Internet with progress bar
    'References : iNet (Microsoft Internet Transfer Control)
    '             ProgressBar (Microsoft Windows Common Controls 6.0 - SP4)
    'Notes      :
    '               Dim dl As DownloadFile      ' istanza della classe
    '               Set dl = New DownloadFile
    '               Set dl.setInet = me.Inet1   ' Imposta il valore di una proprietà dell'oggetto Inet
    '               Set dl.setPrgPercentDone = Me.prgPercentDone ' Imposta il valore di una proprietà dell'oggetto ProgressBar
    '               dl.DownloadFile Me.txtSourceFile.Text, Me.txtDestFile.Text ' richiamo evento
    '               dl.getDownloadingFile       ' (proprietà tipo boolean) il downloading è stato effettuato
    '               dl.getLocalSaveFile         ' (proprietà tipo string) il percorso e nome del file salvato
    '-----------------------------------------------------------------------------
    
    Private m_GettingFileSize     As Boolean
    Private m_DownloadingFile     As Boolean
    Private m_DownloadingFileSize As Long
    Private m_LocalSaveFile       As String
    Private prgPercentDone                  As ProgressBar
    Private WithEvents inetDownloadFile     As Inet
    
    'IL FILE E' STATO SCARICATO
    Private b_DownloadingFile     As Boolean
    
    Private Sub NoInternetConnection(ResponseCode As String, ResponseInfo As String)
    On Error Resume Next
        Select Case ResponseCode
            Case 12007: MsgBox "Non sei connesso ad Internet, oppure il server è temporaneamente offline." & vbCrLf & _
                               "Per favore controlla le impostazioni per l'accesso ad Internet e riprova.", vbOKOnly + vbCritical, "Controlla il tuo collegamento ad Internet"
            Case 35761: MsgBox "Errore durante il trasferimento dei file." & vbCrLf & _
                               "Controlla il tuo collegamento ad Internet e riprova.", vbOKOnly + vbCritical, "Problemi durante il downloading dei file"
            Case Else:  MsgBox "There has been occured a problem while downloading the bizzit files." & vbCrLf & _
                               "Controlla il tuo collegamento ad Internet e riprova.", vbOKOnly + vbCritical, "Problemi durante il downloading dei file"
        End Select
    End Sub
    
    Public Sub DownloadFile(strSrcHTTPFile As String, strDestSaveFile As String)
        m_DownloadingFile = False
        m_DownloadingFileSize = GetHTTPFileSize(strSrcHTTPFile)
        If m_DownloadingFileSize <> -1 Then
            m_LocalSaveFile = strDestSaveFile
            m_DownloadingFile = True
            
            inetDownloadFile.Execute strSrcHTTPFile, "GET " & Chr(34) & strDestSaveFile & Chr(34)
        Else
            MsgBox "Errore sulle informazione del file", vbCritical, "Problemi durante il downloading dei file"
        End If
    End Sub
    
    Private Function GetHTTPFileSize(strHTTPFile As String) As Long
    On Error GoTo ErrorHandler
        Dim GetValue As String
        Dim GetSize  As Long
        m_GettingFileSize = True
        inetDownloadFile.Execute strHTTPFile, "HEAD " & Chr(34) & strHTTPFile & Chr(34)
        Do Until inetDownloadFile.StillExecuting = False
            DoEvents
        Loop
        GetValue = inetDownloadFile.GetHeader("Content-length")
        Do Until inetDownloadFile.StillExecuting = False
            DoEvents
        Loop
        If IsNumeric(GetValue) = True Then
            GetSize = CLng(GetValue)
        Else
            GetSize = -1
        End If
        If GetSize <= 0 Then GetSize = -1
        m_GettingFileSize = False
        GetHTTPFileSize = GetSize
    Exit Function
    
    ErrorHandler:
        m_GettingFileSize = False
        GetHTTPFileSize = -1
    End Function
    
    Private Sub inetDownloadFile_StateChanged(ByVal State As Integer)
    On Error Resume Next
        Dim vtData()  As Byte
        Dim FreeNr    As Integer
        Dim SizeDone  As Long
        Dim bDone     As Boolean
        Dim GetPerc   As Integer
    
        Select Case State ' ... Other cases not shown.
            Case icError: ' 11
                If inetDownloadFile.ResponseCode = 12007 Then
                    NoInternetConnection inetDownloadFile.ResponseCode, inetDownloadFile.ResponseInfo
                End If
            Case icResponseCompleted: ' 12
                If m_GettingFileSize = True Then
                    Exit Sub
                End If
                If m_DownloadingFile = True Then
                    Kill m_LocalSaveFile
                    FreeNr = FreeFile
                    Open m_LocalSaveFile For Binary Access Write As FreeNr
                    Do While Not bDone
                        vtData = inetDownloadFile.GetChunk(1024, icByteArray)
                        SizeDone = SizeDone + UBound(vtData)
                        GetPerc = (SizeDone / m_DownloadingFileSize) * 100
                        If GetPerc > 100 Then GetPerc = 100
                        If GetPerc < 0 Then GetPerc = 0
                        prgPercentDone.Value = GetPerc
                        Put #FreeNr, , vtData()
                        If UBound(vtData) = -1 Then
                            bDone = True
                        Else
                            DoEvents
                        End If
                    Loop
                    Close FreeNr
                    b_DownloadingFile = True
                    MsgBox "File scaricato", vbInformation
                    prgPercentDone.Value = 0
                End If
        End Select
    End Sub
    
    Private Sub Class_Initialize()
        m_GettingFileSize = False
        m_DownloadingFile = False
        b_DownloadingFile = False
    End Sub
    
    Private Sub Class_Terminate()
        Set inetDownloadFile = Nothing
        Set prgPercentDone = Nothing
    End Sub
    
    Public Property Set setInet(ByRef cboData As Inet)
        Set inetDownloadFile = cboData
    End Property
    
    Public Property Set setPrgPercentDone(ByRef cboData As ProgressBar)
        Set prgPercentDone = cboData
    End Property
    
    Public Property Get getLocalSaveFile()
        getLocalSaveFile = m_LocalSaveFile
    End Property
    
    Public Property Get getDownloadingFile()
        getDownloadingFile = b_DownloadingFile
    End Property

  3. #3
    Utente di HTML.it L'avatar di Fado84
    Registrato dal
    Feb 2004
    Messaggi
    347
    Grazie, io non scarico file ma semplicemente salvo le pagine in stringhe..
    codice:
    Esempio0= inet1.OpenURL  "www.html.it"
    Esempio1= inet1.OpenURL  "www.html.it"
    Esempio2= inet1.OpenURL  "www.html.it"
    Esempio3= inet1.OpenURL  "www.html.it"
    Volevo associare a questo la progress bar con un conteggio della percentuale..
    puoi aiutarmi??

  4. #4
    devi modificare un po la classe ed è già fatta

  5. #5
    Utente di HTML.it L'avatar di Fado84
    Registrato dal
    Feb 2004
    Messaggi
    347
    volevo capire come funziona la progress bar.. nella tua classe
    è associata al download di un file io devo scaricare una ventina di pagine

    ciao

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.