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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

anyone know a way of neatening this code...? 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
the code i am using is really elongated, i was wondering if there was a better way of doing this simple task?
all it does is takes the contents of 9 rows of 6 text boxes then puts those values over the max which is the "projtot" value and multiplies by 100

projtot = CDbl(proj1.Text) + CDbl(proj2.Text) + CDbl(proj3.Text) + CDbl(proj4.Text) + CDbl(proj5.Text) + CDbl(proj6.Text)
s9total = (CDbl(s9p1.Text) + CDbl(s9p2.Text) + CDbl(s9p3.Text) + CDbl(s9p4.Text) + CDbl(s9p5.Text) + CDbl(s9p6.Text))
s8total = (CDbl(s8p1.Text) + CDbl(s8p2.Text) + CDbl(s8p3.Text) + CDbl(s8p4.Text) + CDbl(s8p5.Text) + CDbl(s8p6.Text))
s7total = (CDbl(s7p1.Text) + CDbl(s7p2.Text) + CDbl(s7p3.Text) + CDbl(s7p4.Text) + CDbl(s7p5.Text) + CDbl(s7p6.Text))
s6total = (CDbl(s6p1.Text) + CDbl(s6p2.Text) + CDbl(s6p3.Text) + CDbl(s6p4.Text) + CDbl(s6p5.Text) + CDbl(s6p6.Text))
s5total = (CDbl(s5p1.Text) + CDbl(s5p2.Text) + CDbl(s5p3.Text) + CDbl(s5p4.Text) + CDbl(s5p5.Text) + CDbl(s5p6.Text))
s4total = (CDbl(s4p1.Text) + CDbl(s4p2.Text) + CDbl(s4p3.Text) + CDbl(s4p4.Text) + CDbl(s4p5.Text) + CDbl(s4p6.Text))
s3total = (CDbl(s3p1.Text) + CDbl(s3p2.Text) + CDbl(s3p3.Text) + CDbl(s3p4.Text) + CDbl(s3p5.Text) + CDbl(s3p6.Text))
s2total = (CDbl(s2p1.Text) + CDbl(s2p2.Text) + CDbl(s2p3.Text) + CDbl(s2p4.Text) + CDbl(s2p5.Text) + CDbl(s2p6.Text))
s1total = (CDbl(s1p1.Text) + CDbl(s1p2.Text) + CDbl(s1p3.Text) + CDbl(s1p4.Text) + CDbl(s1p5.Text) + CDbl(s1p6.Text))
s9tot.Caption = (s9total / projtot) * 100
s8tot.Caption = (s8total / projtot) * 100
s7tot.Caption = (s7total / projtot) * 100
s6tot.Caption = (s6total / projtot) * 100
s5tot.Caption = (s5total / projtot) * 100
s4tot.Caption = (s4total / projtot) * 100
s3tot.Caption = (s3total / projtot) * 100
s2tot.Caption = (s2total / projtot) * 100
s1tot.Caption = (s1total / projtot) * 100
 
Hi,

Its a little difficult to see what's what in your code, but:
Make your textboxes (and labels? (s?tot)) as arrays and loop through the array to set the caption.

To create control arrays:
Put one label (if that's what they are) on your form, name it, select it and press ctrl+c and ctrl+v to copy it. Vb will now ask you if you want to create an array.

then something like:
------------------------------------------------------------
projtot = CDbl(proj1.Text) + CDbl(proj2.Text) + CDbl(proj3.Text) + CDbl(proj4.Text) + CDbl(proj5.Text) + CDbl(proj6.Text) 'or you could also make an array and a loop
for i=1 to 9
here
stotal = (CDbl(sp1(i).Text) + CDbl(sp2(i).Text) + CDbl(sp3(i).Text) + CDbl(sp4(i).Text) + CDbl(sp5(i).Text) + CDbl(sp6(i).Text))
stot(i).Caption=(stotal/projtot)*100
-----------------------------------------------------------


Sunaj

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top