Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Progressbar To Quick... VB6


Reply
 
Thread Tools Display Modes
  #1  
Old 05-03-2007, 09:51 AM
LittleDevil LittleDevil is offline
Junior Contributor
 
Join Date: Apr 2003
Posts: 247
Question Progressbar To Quick... VB6


Hi Guys

I have a listView control that fills from a recordset and sets a fields name in the listView....this is in a loop untill all names are listed and the user can then click on a name and see a record...

This all works fine.

But on 1 database there are 1000's of names and takes a few seconds to load and I have added a progressbar control onto the form to show the user the % done as a visual aid for large lists.

I put the progress bar code into my recordsets loop and incrimented till the recordset hits EOF and then its done...

This is also working.

But when I load up the large list of names the progressbar shows done well before the list finishes showing all the names and appears off putting a little and wondered what I can do to solve this? Can I slow the progress bar down somehow if there are over a certain amount of records?

Thanks in advance for any help.
L
Reply With Quote
  #2  
Old 05-03-2007, 09:58 AM
JPB JPB is offline
Contributor
 
Join Date: Oct 2004
Posts: 629
Default

I think you just need to change the Max property of your progress bar to the RecordCount of the recordset (if I understood your problem correctly).
Reply With Quote
  #3  
Old 05-03-2007, 05:21 PM
LittleDevil LittleDevil is offline
Junior Contributor
 
Join Date: Apr 2003
Posts: 247
Question

Hi,
Sorry for not being clearer, I will post a snip of my code to show you what Ive done and as far as I see I have set the RecordCount as you mention ..

This is running as I say but the progress bar is done way before the list fills and finally shows all records..

Code:
a = rs.RecordCount
b = 0
ProgressBar1.Max = 100

Do Until rs.EOF
' fill the list in here along with the small list icons

 b = b + 1
    ProgressBar1.Value = CInt((b / a) * 100)
    rs.MoveNext
    
Loop

rs.Close
Set rs = Nothing
Exit Sub
Thats about all I have ...
Any thoughts or suggestions are welcome.
Thanks
Reply With Quote
  #4  
Old 05-03-2007, 06:30 PM
JPB JPB is offline
Contributor
 
Join Date: Oct 2004
Posts: 629
Default

Hmmm, code looks alright to me. Only 2 things that I can think of:

1) Try putting a DoEvents after the rs.MoveNext line. Maybe the ProgressBar is updating itself, but the list is waiting for an opportune moment.
2) What is the value of rs.RecordCount? (try Debug.Print rs.RecordCount). Is it accurate? Depending on the CursorLocation, DB Engine, etc... the RecordCount property can sometimes = -1 or just be an estimation (IIRC). You could try rs.CursorLocation = adUseClient (if you are using ADO for data access, and if it doesn't have a negative impact your requirements) and see if that helps.
Reply With Quote
  #5  
Old 05-03-2007, 06:39 PM
LittleDevil LittleDevil is offline
Junior Contributor
 
Join Date: Apr 2003
Posts: 247
Talking

Thank you,

That was it...
I had a wrong Recordcount getting returned and fixed that and all is well.
Thank you for your help.
L
Reply With Quote
  #6  
Old 05-04-2007, 09:01 AM
PianoMan's Avatar
PianoMan PianoMan is offline
Contributor
 
Join Date: Oct 2003
Location: NC, USA
Posts: 470
Default

Quote:
Originally Posted by LittleDevil View Post
Code:
a = rs.RecordCount b = 0 ProgressBar1.Max = 100 Do Until rs.EOF ' fill the list in here along with the small list icons b = b + 1 ProgressBar1.Value = CInt((b / a) * 100) rs.MoveNext Loop rs.Close Set rs = Nothing Exit Sub

Thats about all I have ...
Any thoughts or suggestions are welcome.

A sugestion. If you're looping through the entire recordset, why not just increment the progressbar each time you move to the next record.
Code:
a = rs.RecordCount b = 0 ProgressBar1.Max = a -1 'set the max to the .RecordCount property Do Until rs.EOF ' fill the list in here along with the small list icons b = b + 1 rs.MoveNext ProgressBar1.Value = ProgressBar1.Value + 1 'increment by 1 each time you loop through DoEvents Loop rs.Close Set rs = Nothing Exit Sub

This way you're ensured that the ProgressBar progress matches what you are doing in the recordset.
__________________
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." ---Rich Cook
Reply With Quote
  #7  
Old 05-04-2007, 10:32 AM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,378
Default

Now, if you have thousands of records, updating the progress bar and issuing a DoEvents for every record is REALLY going to slow down your app. A LOT.

However, if you need to see the bar update, and you have a lot of records, here's a handy workaround: Only update the bar when the change would result in a VISIBLE change in the progress bar. (a change that results in at LEAST one pixel change on the progress bar (that uses smooth scrolling)) Suppose that you have 10000 records, and your progress bar is 200 pixels wide. This means that you only need to update the progress bar every 50 records! (10000 Records/200 pixels = 50 records/pixel ) Note that if you are using a progress bar with standard scrolling, each "step" is about 15 pixels wide...

You're already keeping track of your current record number. before you begin your loop, calculate the number of pixels in your progress bar, then calculate the records per pixel. Then, inside the loop, only update the bar when needed.

Code:
Const TwipsPerInch as Integer = 1440 ' useful for scalemodes other than twips/pixels Const intStdScrollScale as Integer = 15 Dim lngCurrentRecord as long Dim lngRecPerPixel as Long Dim lngNumRecs as Long lngNumRecs = rs.Recordcount ' (Or, issue a select count SQL statement first) ' calculate the number of records per pixel Select Case me.Scalemode Case 1 'twips lngRecPerPixel = rs.RecordCount\(me.ProgressBar1.Width/Screen.TwipsPerPixelX) Case 3 ' Pixels lngRecPerPixel = rs.RecordCount\me.ProgressBar1.Width Case Else lngRecPerPixel = 1 ' You'll need to work out any other scale modes ' yourself, remembering that there are 1440 twips per inch. End Select ' account for progress bar scroll mode If me.ProgressBar1.Scrolling = ccScrollingStandard then lngRecPerPixel = lngRecPerPixel * intStdScrollScale End If ' Since the number of records COULD exceed 32767, always use percentage, ' rather than actual record number Me.ProgressBar1.Max = 100 ' percent Do Until rs.EOF ' fill the list in here along with the small list icons lngCurrentRecord = lngCurrentRecord + 1 rs.MoveNext ' ONLY if we need to, calculate percentage & update... If lngCurrentRecord Mod lngRecPerPixel = 0 Then ProgressBar1.Value = cSng(lngCurrentRecord / lngNumRecs * 100) DoEvents End If Loop
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown

Last edited by loquin; 05-04-2007 at 10:48 AM.
Reply With Quote
  #8  
Old 05-05-2007, 07:04 PM
LittleDevil LittleDevil is offline
Junior Contributor
 
Join Date: Apr 2003
Posts: 247
Thumbs up Thats very clever, Thank you.....

The DoEvents did indeed slow it down dramatically so I took it out right away...

Thanks again
L
Reply With Quote
  #9  
Old 05-07-2007, 09:18 AM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,378
Default

However, without the DoEvents, you won't see any changes in the progress bar until the loop is done. Which, really defeats the purpose of a progress bar, doesn't it???

As I posted earlier, just update the progress bar and issue a DoEvents ONLY when a change in the progress bar .Value would result in a visible change in the progress bar.
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->