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 POPULATING TXT BOXES EATING UP LOAD TIME 3

Status
Not open for further replies.

TNN

Programmer
Sep 13, 2000
417
US
I have a For Loop that takes 8 to 9 seconds to load and complete in the form load event. I am filling 199 text boxes with data from a data base. The user does this numerous times during the course of processing data.
How can I reduce the load time or is there another approach to this??? Thank you in advance for any help.

My code below:

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

Select Case n 'Numbers below are indexes for 1st column of text boxes.
Case 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190
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


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

TNN, Tom
TNPAYROLL@AOL.COM


TOM
 
You're not doing anything wrong here -- you're just doing a lot of work!

To speed things up, you might want to surround your loop with a "With objSource"..."End With" block. If the objSource is in another module/class/whatever, VB takes a little longer to resolve it that if it were local. The With block does that work up front, rather than each time you access a method/property.

You might also try coding your access to the ado recordset like this:

adoRsPyrlCalc2("FieldName")

instead of using the exclamation point (I think that operator is going away in VB 7).

Chip H.



 
On your pc of on the pc of the User ?

I have a For Loop that takes 8 to 9 seconds to load and complete in the form load event. I am filling 199 text boxes with data from a data base. The user does this numerous times during the course of processing data.

The problems is he of she see the textboxs before it loading the data whit in,to sove that after you code set :

Me.Show Eric De Decker
vbg.be@vbgroup.nl

License And Copy Protection AxtiveX.

Download Demo version on my Site:
 
Eric -

Good point. If the form is visible while you're trying to populate the controls it will take longer as VB paints each individual textbox. Hide the form, load the controls, and then make it visible again. Should speed things up.

Chip H.
 
Thank you,
chiph,
edderic,

chiph,
Thank You for your interp of edderic's comments. I was having trbl understanding just what edderic was saying.

edderic,
No offence please. I truly appreciate your input. I Love ya man.

I will attempt to institute all of the above and see what kind of improvement I see. If you would like me to report back, I will.
Thanks again guys, sooooo much.
TNN, Tom
TNPAYROLL@AOL.COM



TOM
 
Two thoughts:

Design: When I read that you need 200 TextBoxes on a form, I systematically wonder why you should need that many. It is my conviction that a (normal) user is unable to manage 200 textboxes to input data, because that's why a Textbox is used for. It should ideally not be used just to display data. You then should use Labels instead.

And even then: 200 Labels is a hell of a lot. Are you sure, you're not re-inventing a Grid Control? It could be used with much more efficiency. If for some reason you can't use that control then implement Eric's advise and hide the Labels while updating.

Coding: I stripped the coding to lay down its loop structure and unless I overlooked something, the following skeleton was revealed:

For n = 0 To 199 Step 10
Select n
Case 0,10,20,30, ...... 190
End Select
Next n


Have a close look at it: Do you think that n can be anything else than a multiple of 10? I do not blindly trust MicroSoft's VB, but in this case I'm pretty sure that you can drop the entire Select structure. Don't forget that before getting to the 190, VB has already tested if n=0,10,20, ... , 180 only to find all of them false.

BTW: I didn't find any Dims in your code. Be sure to include at least an explicit declaration for n e.g.Dim n As Integer, otherwise it will be a variant. And Variants in a loop control are real performance killers.

_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
, but in this case I'm pretty sure that you can drop the entire Select structure. Don't forget that before getting to the 190, VB has already tested if n=0,10,20, ... , 180 only to find all of them false.

I think TNN was unrolling the loop by a factor of 10 in an effort to get more performance out of it. Common technique in games programming. Although the Select statement may eat up any gains...

Dim n As Integer, otherwise it will be a variant. And Variants in a loop control are real performance killers.

Good point. Using the correct datatype for a loop variable is important.

Chip H.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top