Results 1 to 6 of 6

Thread: PROGRESS BAR!!!!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    95
    How do I use the progress bar to measure how long it will take for to do something.

    for example, I am making a program that encrypts text, but it takes longer for larger files, so i want to display a progress bar. how do i do it?

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    You don't neccessarily need to use the Progressbar, you can achieve the same effect with a picturebox, i.e.
    Code:
    Private Sub Command1_Click()
        Dim iFile As Integer
        Dim sFile As String
        Dim nChar As Long
        
        iFile = FreeFile
        Open "D:\LargeFile.txt" For Binary Access Read As iFile
        sFile = Space(LOF(iFile))
        Get #iFile, , sFile
        Close iFile
        
        nChar = 1
        While nChar <= Len(sFile)
            'Do whatever with each character of the file
            nChar = nChar + 1
            If nChar Mod 10 = 0 Or nChar = Len(sFile) Then
                Picture1.Line (0, 0)-((Picture1.ScaleWidth / Len(sFile)) * nChar, Picture1.ScaleHeight), vbBlue, BF
            End If
        Wend
    End Sub
    You can vary the update period to suit your own needs.

  3. #3
    Guest
    I was searching through my files and the results:

    Code:
    'Using the Progress Bar to measure action:
    
    ProgressBar1.Max=1000        
    'Then in a later loop where I am displaying progress as I move through a file, my code says:
    
    ProgressBar1.Value=X mod 1000        
    'X is a count of records read from a file, which I have no way of knowing the number of records beforehand. This way, using MOD,  I never have an out of range error in setting the progress bar value.  Once the number of records is over 1000, then using MOD, the progressbar is reset to 0.
    OR:
    Code:
    'strSource As String (String To work with)
    'Optional strKey As String = "jhGd&34" (The key)
    'EncDecFile:
    'strSource As String (full path of file To work with)
    'Optional bolShowProgress As Boolean = False (self-Explanatory)
    'Optional objProgress As ProgressBar (The actual Prog.Bar)
    
    Public Function EncDecString(strSource As String, Optional strKey As String = "jhGd&34") As String
        Dim i As Integer
        Dim intAscSource As Integer
        Dim strTempEncDec As String
        Dim strSeed As String
        Dim intkey As Integer
        'generates Seed for the randomize event 
        '     through Ascii codes of each of the chara
        '     cters of the key
    
    
        For i = 1 To Len(strKey)
            strSeed = strSeed & Asc(Mid(strKey, i, 1))
        Next i
        Rnd -1'Because i want To work With the same random table
        Randomize CDbl(strSeed)
    
    
        For i = 1 To Len(strSource)
            intkey = Int(256 * Rnd) 'generates an Integer (0-255)
            intAscSource = Asc(Mid(strSource, i, 1))
            strTempEncDec = strTempEncDec & Chr(intAscSource Xor intkey) ' The actual encryption takes place here
        Next i
        EncDecString = strTempEncDec
    End Function
    '***************************************
    '     *******************'
    
    
    Public Sub EncDecFile(strSource As String, Optional bolShowProgress As Boolean = False, Optional objProgress As ProgressBar)
        Dim iFile As Integer
        Dim StrStream As String * 100
        Dim lngSteps As Long
        Dim i As Long
        iFile = FreeFile()
        Open strSource For Binary As iFile
        'Help me on this one, please.
        'How can i avoid this and work on the en
        '     tire file?
        'I had difficulty trying to deal with th
        '     e Seek statement.
        'If you notice, i'm working on 100 bytes
        '     segments and discarding the last <=99
        '     bytes.
        lngSteps = Int(LOF(iFile) / 100)
        'inicializes the progress bar.
    
    
        If bolShowProgress Then
            objProgress.Min = 0
            objProgress.Max = lngSteps
            objProgress.Value = 0
        End If
    
    
        For i = 1 To lngSteps
            Get iFile, i, StrStream
            StrStream = EncDecString(StrStream) 'calls the Function above where the encryption takes place.
            Put iFile, i, StrStream
    
    
            If bolShowProgress Then 'Updates the progress bar
                objProgress.Value = i
            End If
        Next i
        Close iFile
    End Sub

  4. #4
    Guest
    You should use ARGradient as a Progressbar. It's much better than the standard Windows one. I'll see if I can find the site for you.

  5. #5
    Junior Member
    Join Date
    May 2000
    Location
    Milwaukee, Wi
    Posts
    28
    the progress bar is very simple to use. Just the max property to any arbitrary amount. 100 is a good number to start out with. Then just find a loop in your program that handles the bulk of the time-consuming calculations and increment the progressbar at th eend of each iteration of the loop. here, kinda like this:


    progressbar1.max = 100

    for x = 1 to 100
    do this
    do this
    do this
    progressbar1.value = x
    next x

    if the max iteration of your loop is greater than 100

    for x = 1 to 2000
    do this
    do this
    progressbar1.value = x mod 100
    next x

    shaheeb

  6. #6
    Guest
    But if he doesn't know how large the file is going to be, there is no fixed interval.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width