I have an ASP page that loops through a database and adds up score results and adds up the number of results (to be later used to determine the score). For each score item I check and make sure none of the database fields are empty or contain 999 (what I am sending instead of empty data so none should be empty technically).
I reuse the following code a good 15 times with each different variable name (the variables being curA1, curA2, curA3, etc. and curA1Num, curA2num, curA3num, etc.) I know there has to be better code than an endless page of ifs. How do I not repeat my code for each variable? I offer sincere thanks to whomever has an answer to what is currently a long and very badly structured ASP page.
Overly reused code:
Expand|Select|Wrap|Line Numbers
- if rs.fields("A1")<>"" then
- if rs.fields("A1")<>999 then
- curA1 = curA1 + rs.fields("A1")
- curA1Num = curA1Num + 1
- end if
- end if
Expand|Select|Wrap|Line Numbers
- <%= Int(curA1/curA1Num) & "%" %>
A novice ASP programmer