Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: how can i get this data?


Message #1 by stephen.eighmey@s... on Thu, 21 Feb 2002 22:14:22
hello,



  i am hoping that someone can help me with this issue.

i have a form that has 34 questions that are checkboxes that have the 

value of either yes or no, or you just don't select one and it's not 

included. each of these questions has a particular point value assigned to 

it; most are 1, some are 2 and a few are 10. the end result is that i need 

to provide a score based on the answers to these questions. the formula is 

for me to find all the questions that were answered "yes" and determine 

the total point value for all the yes questions (depending on what point 

value is assigned to that particular question), then find all the 

questions that were answered "no", get the total point value for these 

questions and then manipulate these variables to provide the score.



can someone suggest a way i can do this? 



ps. i've thought about hard coding the point value for each question into 

the form and then looping through this dataset, but the value is already 

assigned to each question of either yes or no.



thank you.
Message #2 by stephen.eighmey@s... on Thu, 21 Feb 2002 23:33:09
okay, i'm working on an answer. maybe someone can tell me if this might 

work or not. 



i've set a hidden field in each of my questions that looks like this...



<p align="left"><font face="Verdana" size="2">Yes</font> 

          <input type="checkbox" name="24" value="yes">

          <font face="Verdana" size="2">No</font> 

          <input type="checkbox" name="24" value="no">

          <input type="hidden" name="pointValue" value="4">

          <font face="Verdana" size="2">&nbsp;&nbsp;<b>24.</b> Did Agent 

create/close the case and add notes utilizing note-taking template?

</font></p>



each question has this exact same hidden field component except that the 

value might be different for each one. the name="pointValue" is exactly 

the same for each question



now here is my asp code that, ideally, will total the point value for 

all "yes" answers and all "no" answers...



Dim pointValue, pointValueYes, pointValueNo, newTotal, varScore

pointValue = Request.Form("pointValue")



pointValueYes = 0

for each checkbox in Request.Form

do while checkbox value = "yes"

get pointValue

pointValueYes = (pointValueYes + pointValue)

loop

end while



pointValueNo = 0

do while checkbox value = "no"

get pointValue

pointValueNo = (pointValueNo + pointValue)

loop

end while

next

newTotal = (pointValueYes + pointValueNo)

varScore = (pointValueYes/newTotal)



the first error i'm getting is an "expected statement" for the first 

instance of "get pointValue"



any help is most appreciated. thank you.
Message #3 by "Ken Schaefer" <ken@a...> on Fri, 22 Feb 2002 10:55:23 +1100
This is a multi-part message in MIME format.



------=_NextPart_000_01E9_01C1BB8F.6D5B1E10

Content-Type: text/plain;

	charset="Windows-1252"

Content-Transfer-Encoding: quoted-printable



Why don't you just store the values for each question in the database?

Then you can do a lookup when you need to calculate someone's score.

The method you have is open to abuse, as anyone can alter you page to 

set whatever score they like for each question.



Now, with the error you are getting:



: do while checkbox value =3D "yes"

: get pointValue



The above lines aren't valid VBScript...you should be getting an error 

on:



: do while checkbox value =3D "yes"

-------------------^



...where the ^ is

Also, your code has a logical flaw. You need to loop through the whole 

request.form collection and test *each* checkbox to see if it is "yes". 

At the moment, with the Do While...Loop, the loop will stop as soon as 

it gets to the first  "no" value, even if there are more questions later 

on that were answered "yes"



Cheers

Ken



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From: <stephen.eighmey@s...>

Subject: [asp_databases] Re: how can i get this data?





: okay, i'm working on an answer. maybe someone can tell me if this 

might

: work or not.

:

: i've set a hidden field in each of my questions that looks like 

this...

:

: <p align=3D"left"><font face=3D"Verdana" size=3D"2">Yes</font>

:           <input type=3D"checkbox" name=3D"24" value=3D"yes">

:           <font face=3D"Verdana" size=3D"2">No</font>

:           <input type=3D"checkbox" name=3D"24" value=3D"no">

:           <input type=3D"hidden" name=3D"pointValue" value=3D"4">

:           <font face=3D"Verdana" size=3D"2">&nbsp;&nbsp;<b>24.</b> Did 

Agent

: create/close the case and add notes utilizing note-taking template?

: </font></p>

:

: each question has this exact same hidden field component except that 

the

: value might be different for each one. the name=3D"pointValue" is 

exactly

: the same for each question

:

: now here is my asp code that, ideally, will total the point value for

: all "yes" answers and all "no" answers...

:

: Dim pointValue, pointValueYes, pointValueNo, newTotal, varScore

: pointValue =3D Request.Form("pointValue")

:

: pointValueYes =3D 0

: for each checkbox in Request.Form

: do while checkbox value =3D "yes"

: get pointValue

: pointValueYes =3D (pointValueYes + pointValue)

: loop

: end while

:

: pointValueNo =3D 0

: do while checkbox value =3D "no"

: get pointValue

: pointValueNo =3D (pointValueNo + pointValue)

: loop

: end while

: next

: newTotal =3D (pointValueYes + pointValueNo)

: varScore =3D (pointValueYes/newTotal)

:

: the first error i'm getting is an "expected statement" for the first

: instance of "get pointValue"

:

: any help is most appreciated. thank you.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~






Message #4 by "Ken Schaefer" <ken@a...> on Fri, 22 Feb 2002 12:07:44 +1100
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From: "Ken Schaefer" <ken@a...>

Subject: [asp_databases] Re: how can i get this data?





: Also, your code has a logical flaw. You need to loop through the

: whole request.form collection and test *each* checkbox to see if it is

"yes".

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Sorry, that should read:



"You need to loop through the whole Request.Form("checkbox") collection..."



but the point remains the same - your loop (at present) will stop when it

reaches the first non-"yes" value, regardless if there are any more

questions later on that are "yes"



Cheers

Ken




  Return to Index