473,410 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Dynamically generated Variables

Hi,
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
  1. if rs.fields("A1")<>"" then 
  2.   if rs.fields("A1")<>999 then
  3.     curA1 = curA1 + rs.fields("A1")
  4.     curA1Num = curA1Num + 1
  5.   end if
  6. end if
My score is later displayed in a field using:
Expand|Select|Wrap|Line Numbers
  1. <%= Int(curA1/curA1Num) & "%" %>
Thanks,
A novice ASP programmer
Nov 8 '06 #1
1 1083
AricC
1,892 Expert 1GB
Have you tried a case statement? That will clean it up a bit.
Nov 9 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Dave Nouwens | last post by:
Hi All, Please accept my appologies in advance for what I expect will be a reasonably simple question. I have an html form (which is generated in php) which contains a number of rows (one row...
8
by: Falc2199 | last post by:
Hi, Does anyone know how to make this work? var sectionId = 5; repeat_section_sectionId(); function repeat_section_5(){ alert("firing"); }
4
by: EmmettPower | last post by:
Hi, I have a form which includes a field 'number'. When 'number' is changed additional fields ('item_0', etc) are generated on the form using 'onchange'. I want to validate the form using...
4
by: vertigo | last post by:
Hello I need to create some objects durring program execution - but it's names are dynamically generated (depends on parameters). How can i do it ? Thanx Michal
2
by: Maziar Aflatoun | last post by:
Hi everyone, Here is the basic idea. I have a form that opens up a new window ViewNote.aspx sending 3 parameters. <INPUT class="buttonsmall" id="NewNote1" type="button" value="New Note"...
2
by: david | last post by:
I have no idea how to get the IDs of dynamically genrated CheckBoxes and the events of CheckedChange. I have dynamically generated array of CheckBoxes, checkboxes,which dynamically display in a...
7
by: pmclinn | last post by:
I was wondering if it is possible to dynamically create a structure. Something like this: public sub main sql = "Select Col1, Col2 from Table a" dim al as new arraylist al =...
27
by: ted benedict | last post by:
hi everybody, i hope this is the right place to discuss this weird behaviour. i am getting dynamically generated text or xml from the server side using xmlhttprequest. if the server side data is...
1
by: vega80 | last post by:
Hi. I have a problem with assigning an onkeypress-function to dynamically created input-boxes.I want to put the content of an input-field into a tag-list when the user hits enter. This works...
1
by: =?Utf-8?B?bWFya203NQ==?= | last post by:
I have a simple page i'm trying to do dynmaically.. i have a page called submitcomments.aspx with the .cs codebehind.. before i created everything in design view.. now i've ripped that out and...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.