Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FOR LOOP TAKES TOOOO LONG TO POPULATE TEXT BOXES 3

Status
Not open for further replies.

TNN

Programmer
Sep 13, 2000
417
US
This FOR loop takes approx 8.5 seconds to populate 96 text boxes. I need to get this down to 1 second. Possible??
What is taking this thing so long???? There are only 20 iterations in the loop. What in this code is the holdup???
Why is it that a db grid will populate sooo much faster????
Adapting a db grid to my app would be a monumental chore.
Any help??
Thank You.

For n = 0 To 199 Step 10 'Step 10 provides index for 1st column text box for ea row.

If objSource.adoRsPyrlCalc2.EOF = True Then Exit For

i = n 'Load fields from recordset into text boxes. Below loads
'one row.
txt1(i).Text = objSource.adoRsPyrlCalc2!WAGENAME
i = i + 1
txt1(i).Text = objSource.adoRsPyrlCalc2!WageNo
'Load array and advance index for use in proc CalcGross and
'proc PostWageTypes.
WageNos(A) = objSource.adoRsPyrlCalc2!WageNo
If A = 20 Then 'If this is twentieth wage then no more WageNos to store.
'Do not increment array index for next array WageNos.
Else
A = A + 1 'Do increment A if A is less than 20. If this is last
'wage being loaded then A will be 1 larger than
'last wage number loaded into array WageNos.
End If
i = i + 1
txt1(i).Text = objSource.adoRsPyrlCalc2!DEPT
i = i + 1
'txt1(i).Text = objSource.adoRsPyrlCalc2! (Future Use)
i = i + 1
txt1(i).Text = objSource.adoRsPyrlCalc2!WRATE
'Pass WAGENO and i to procedure PostWageTypes.
PostWageTypes objSource.adoRsPyrlCalc2!WageNo, i
'This bookmarks the record for each row of textboxes by using the
'Txt1 index of the WRATE textbox as an item(index) of the
'bookmark array to bookmark each record.
'The Txt1 WRATE Gotfocus event then calls the bookmark to make
'that row of textboxes the current record and then binds the
'WRATE textbox so that the user can then edit the WRATE textbox.
BkMrk(i) = objSource.adoRsPyrlCalc2.Bookmark
i = i + 5
txt1(i).Text = objSource.adoRsPyrlCalc2!YTD_AMT

objSource.adoRsPyrlCalc2.MoveNext 'Iterate through all wages for employee.
Next n

TNN, TOM
TNPAYROLL@AOL.COM

TOM
 
It seems that you're not just filling text boxes with the loop, but also making a call to
Code:
 PostWageTypes objSource.adoRsPyrlCalc2!WageNo, i
for each itteration. Could this be the bottleneck?

Mark
 
Tom,
You've posted this question a number of times, and I think that rvBasic answered it best (thread222-66717 03/30/2001).
He suggesed that if you are only displaying data, then the label control (which can have its properties set so that it looks just like a textbox) will require fewer resources.
Still, just switching the textboxes to labels may not be enough for what you are trying to do . . . to me (as it was to rvBasic), it sounds as though you are trying to reinvent the Grid Control and I would really recommend that you consider using a grid control for what you are tyring to do. I know that you mentioned that it will take a great deal of work to change your app at this point to use a grid control (I have to ask at this point, why didn't you just start assuming that this would be a grid control), but if you really want the speed, you may just have to bite the bullet and do it. Its like they say . . . the right tool for the right job. Of course there may be a design requirement that you have not mentioned that prohibts the use of the grid control.
MarkSweetland also mentions a good point . . . what does
Code:
PostWageTypes
do and is it really required for each iteration of your loop. How much of the work is being performed inside of this method call?
Also, it seems like you are setting bookmarks so that you can bind specific records to your control at runtime to allow the user to update the data? (If I read your comments wrong, please correct me) Normally, I stay away from any control binding since it normally kills performance. Let the user edit the fields they need to be able to edit and then save all of the data when they are finished (i.e. they leave the screen or click an Apply, Save, or OK button). But not haveing to track the bookmark may save you same time as well.
Also, I believe the it was ChipH who suggested the you use a With Block. This will speed up your code (espicially since it is in a loop). This allows the computer to only have to resolve the pointer to the object once, rather than having to do it for every single call inside of the loop.
and yes, ChipH was correct when he mentioned that the Bang notation (rs!field) is considered obsolete and it is going away. I don't know if that will help your performance at all.
Finally, if the screen is redrawing itself while you are populating these fields, that will really slow you down. Make sure that the screen does not refresh itself until AFTER all of the textboxes have been populated.
OK, I've said more than enough . . . but these are just a few thoughts that I had regarding your post. I hope something in all of this ranting helps you . . . - Jeff Marler B-)
 
Thank you Jeff for all of your input.

I did in fact try the WITH Block with no increase in performance. I also tried hideing the form until loaded with no increase in performance.

There are some places where I can use labels but I doubt if much will be gained there.

I Don't know if the grid control will fill my needs as I am not real familiar with them. Will have to investigate.

I did eliminate the bang ! with no increase in performance.

The PostWageTypes is necessary but I could probably use labels where this proc is concerned.

The bookmarking and binding you bring up I will have to consider.

Thanks again Jeff for all of your input. I will consider it all.
TNN, TOM
TNPAYROLL@AOL.COM

TOM
 
Mark,

That was it!!!, called proc "PostWageTypes" was the holdup. Takes 7.5 of the 8.5 seconds to process. Never occurred to me. Thank You Mark.

Now I have to figure out what to do. Maybe SQL statement to pull up all applicable wage types at once. Currently I am using a select case to find all the applicable wage types.

Anyway, Thanks again

Jeff,
Thanks for bringing Mark's comment about PostWageTypes to my attention again.

TNN, TOM
TNPAYROLL@AOL.COM


TOM
 
TNN -

Glad you were able to spot your performance problem. As always, until you document where your code is spending your time, you don't know where the bottlenecks are ocurring.

The "Bang" operator (exclamation point) would not have given you any increase in performance, but simply prepares you for the next release of VB. If your loop were tighter (and didn't involve database access) I would expect the With..EndWith to have given you some speed increase.

Do you subscribe to Visual Basic Programmer's Journal or one of the other developer's magazines? If not, now is the time. With the release of VB7 (VS.NET), the magazines are giving serious coverage to the new stuff in the next release. They won't be repeating this info once VB7 hits the street, so you need to get current copies, plus the past 4-5 months back-issues, and hold onto them. They'll be terrific reference material when VB7 comes out.

I think your suggestion of caching the WageTypes table in a collection is a good candidate for further speed increases (provided there are less than 250-500 rows in the table). You're trading memory for disk access, in this case. If the WageType table isn't updated that often, you could even load the collection up when your application starts and leave it in memory the whole time.

Chip H.
 
Thanks Chip H. for your input.

I did subscribe to Visual Basic Programmer's Journal but let my subscription run out. Maybe should re-up.

TNN, TOM
TNPAYROLL@AO.COM


TOM
 
I did subscribe to Visual Basic Programmer's Journal but let my subscription run out. Maybe should re-up.

Yeah, it's not bad. I just skip over the dopey suggestions that readers send in (just to get the free t-shirts, I think!). Things like "Use the addition operator (+) to add two numbers together".

But every now and again they have an article that is very timely and useful, and justifies the cost of the subscription.

Chip H.
 

"Use the addition operator (+) to add two numbers together"


Wow! Who would've thought it?

OK, sarcasm aside, I have to agree with Chip on VBPJ. There ae some really good articles in there and it is well worth the money . . . just be sure to skip over the lame stuff (you'll know them when you see them). - Jeff Marler B-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top