Results 1 to 9 of 9

Thread: PROGRESSBAR until load form is finisshed

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    2,171

    PROGRESSBAR until load form is finisshed

    in form MENU have this button


    Code:
    Private Sub Command2_Click()
    
        Screen.MousePointer = vbHourglass
    
        Me.Text1.SetFocus
        ROOM.Show (1)
    
        Screen.MousePointer = vbDefault
    
    End Sub
    ROOM form takes a long time to show, because load a big number of recordset

    possible to show a progressbar in MENU form, run it during the recordset load and stop when ROOM form appera?

    sorry for my bad english:-)

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,915

    Re: PROGRESSBAR until load form is finisshed

    couple things (NOT answering your question):

    try to use recommended naming conventions for forms, like frmMenu and frmRoom instead of Menu and Room (keeps things a bit clearer)
    why are you setting focus to the textbox on the Menu form...makes little sense.

    have you TRIED it yourself? Have you put a progressbar on that form? You need to look up how to make a progressbar 'progress'...it needs data (obviously, in your case, from the query you use to load (and display???) the recordset).
    Sam I am (as well as Confused at times).

  3. #3
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,815

    Re: PROGRESSBAR until load form is finisshed

    Luca do some research on ...
    Code:
    rs.AbsolutePostion
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,623

    Re: PROGRESSBAR until load form is finisshed

    You can show your form before you load the recordset and then if you wish use a progress bar on that form to show to progress of the rs loading.

    Since you appear to be showing the form modally it does not make sense to try and show a progress bar on the menu form.

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,501

    Re: PROGRESSBAR until load form is finisshed

    Here's a demo doing something like what you seem to want.

    It has a "menu" Form with a ProgressBar. If it doesn't find any data it will create tab-delimited text data using random values.

    Click the command button to load and show the "child" Form. This Form will read the data and render it as colorful circles, reporting progress back to the "menu" Form as it works.


    A VB6 Form is a Class with additional features making it a control container window. That means it can expose properties, methods, and events. Events are the first go-to when it comes to communicating back to the client (in this case the "menu" Form). The other is a COM callback, but that's probably an even harder thing to explain.

    Just as a lot of programmers don't know how to use a Class or UserControl to encapsulate code and data they also don't know how to use a Form. This stuff is all pretty well spelled out (with examples) in the MSDN documentation for VB6.


    Note: To keep things simple this demo uses the Jet Text IISAM instead of creating an MDB to open. One caveat is that IDE runs may fail with a "collating sequence" phantom exception. This is a well known bug in the VB6 IDE that was never fixed. Ignore this exception and run again. It won't occur in the compiled EXE.
    Attached Files Attached Files
    Last edited by dilettante; May 30th, 2021 at 08:26 PM. Reason: No DoEvents

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,623

    Re: PROGRESSBAR until load form is finisshed

    I find that calling the refresh method of the progress bar works just fine in most cases. In some cases a call to refresh of the form or container is needed but almost never actually need to call do events.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,501

    Re: PROGRESSBAR until load form is finisshed

    The "version 5" OCX that uses the system ProgresBar doesn't have a Refresh method. The "version 6" OCX does, but that has its own issues and limitations. For example a CC6 manifest can't get you the new system control with its enhanced appearance and capabilities since 1998 when "version 6" was frozen in time.

    Maybe sending it the WM_PAINT message directly will work?

    Ahh yes, that did it. Reposted with no DoEvents calls.

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,501

    Re: PROGRESSBAR until load form is finisshed

    Here's the code in the child Form:

    Code:
    Option Explicit
    
    Public Event LoadProgress(ByVal Value As Integer)
    
    Public Sub ReloadThenShow(ByVal Owner As Form)
        Dim Connection As ADODB.Connection
        Dim RowCount As Long
        Dim Color As ADODB.Field
        Dim Radius As ADODB.Field
        Dim X As ADODB.Field
        Dim Y As ADODB.Field
        Dim I As Long
        Dim PercentComplete As Double
    
        AutoRedraw = True
        Cls
        Set Connection = New Connection
        Connection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='.\DB';" _
                      & "Extended Properties='Text'"
        With New ADODB.Recordset
            .CursorLocation = adUseServer
            'Get RowCount for progress:
            .Open "SELECT COUNT(*) FROM `Table.txt`", _
                  Connection, _
                  adOpenForwardOnly, _
                  adLockReadOnly, _
                  adCmdText
            RowCount = .Fields(0).Value
            .Close
            'Firehose the data and render it with progress:
            .Open "Table.txt", Connection, adOpenForwardOnly, adLockReadOnly, adCmdTableDirect
            Set Color = .Fields("Color")
            Set Radius = .Fields("Radius")
            Set X = .Fields("X")
            Set Y = .Fields("Y")
            Do Until .EOF
                FillColor = Choose(Color.Value, _
                                   vbCyan, vbYellow, vbGreen, vbBlue, vbMagenta, vbRed, _
                                   &HE0E0FF, &HFFC080)
                Circle (X.Value, Y.Value), Radius.Value
                I = I + 1
                PercentComplete = (CDbl(I) / RowCount) * 100
                If PercentComplete = Int(PercentComplete) Then
                    RaiseEvent LoadProgress(Int(PercentComplete))
                End If
                .MoveNext
            Loop
            .Close
        End With
        AutoRedraw = False
        Show vbModal, Owner
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        If UnloadMode = vbFormControlMenu Then
            Cancel = True
            Hide
            'We're just hiding to continue instead of wastefully unloading, so it is sort of
            'silly for ReloadThenShow() to redraw everything because we'll just load the same
            'data.  But this is just a demo.
            '
            'In a real program the query might return a subset of Table.txt rather than all
            'of the rows.
        End If
    End Sub
    The menu Form calls frmChild.ReloadThenShow() rather than crudely calling the Show method itself. This gets you better modal dialog behavior.

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,501

    Re: PROGRESSBAR until load form is finisshed

    By rights that method should have:

    Code:
        Connection.Close
    ... near the end after closing the Recordset the second time. But block exit will close the well behaved ADODB.Connection for us anyway.

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