Help Looping Through Survey Questions

C

Colin Steadman

I've create a simple survey using ASP. Its finished and
works, but one aspect of my coding is annoying me and I
cant figure out a better way of doing it.

Basically the questions are stored in an Access 2000 table
like this:

QUESTION_NUMBER QUESTION
1 Question 1 text....
2 Question 2 text....
3 Question 3 text....
4 Question 4 text....
5 Question 5 text....

My ASP page gets these questions and displays them in a
form dynamically. The user then answers the questions by
clicking radio buttons (Agree, Tend to agree, Not sure...
ect).

This works well and if I want to add a question I just
update the database table.

The problem is I've not been able to figure out how to
make the submit page dynamic. I'm having to manually add
code to my submit page to look after each question
individually rather than looping through the Form
collection.

For example when I build the SQL to update the database I
have to do it like this (note the last five lines look
after the responses to my five questions):

ReDim sqlValues(40)

sqlValues(0) = "values ("
sqlValues(1) = "'" & Session("emp_no") & "', "
sqlValues(2) = "'" & Session("Username") & "', "
sqlValues(3) = "'" & Session("sex") & "', "
sqlValues(4) = "'" & Session("phone") & "', "
sqlValues(5) = "'" & Session("job_title") & "', "
sqlValues(6) = "'" & Session("department") & "', "
sqlValues(7) = "'" & Session("age") & "', "
sqlValues(8) = "'" & Session("grade") & "', "
sqlValues(9) = "'" & Request.Form("1") & "', "
sqlValues(10) = "'" & Request.Form("2") & "', "
sqlValues(11) = "'" & Request.Form("3") & "', "
sqlValues(12) = "'" & Request.Form("4") & "', "
sqlValues(13) = "'" & Request.Form("5") & "', "
...

sql = Join(sqlValues)

Is there any possible way I can avoid having to hard code
the above and have the page work out what it needs to do
dynamically?

TIA,

Colin
 
T

Tom Kaminski [MVP]

Colin Steadman said:
I've create a simple survey using ASP. Its finished and
works, but one aspect of my coding is annoying me and I
cant figure out a better way of doing it.

Basically the questions are stored in an Access 2000 table
like this:

QUESTION_NUMBER QUESTION
1 Question 1 text....
2 Question 2 text....
3 Question 3 text....
4 Question 4 text....
5 Question 5 text....

My ASP page gets these questions and displays them in a
form dynamically. The user then answers the questions by
clicking radio buttons (Agree, Tend to agree, Not sure...
ect).

This works well and if I want to add a question I just
update the database table.

The problem is I've not been able to figure out how to
make the submit page dynamic. I'm having to manually add
code to my submit page to look after each question
individually rather than looping through the Form
collection.

For example when I build the SQL to update the database I
have to do it like this (note the last five lines look
after the responses to my five questions):

ReDim sqlValues(40)

sqlValues(0) = "values ("
sqlValues(1) = "'" & Session("emp_no") & "', "
sqlValues(2) = "'" & Session("Username") & "', "
sqlValues(3) = "'" & Session("sex") & "', "
sqlValues(4) = "'" & Session("phone") & "', "
sqlValues(5) = "'" & Session("job_title") & "', "
sqlValues(6) = "'" & Session("department") & "', "
sqlValues(7) = "'" & Session("age") & "', "
sqlValues(8) = "'" & Session("grade") & "', "
sqlValues(9) = "'" & Request.Form("1") & "', "
sqlValues(10) = "'" & Request.Form("2") & "', "
sqlValues(11) = "'" & Request.Form("3") & "', "
sqlValues(12) = "'" & Request.Form("4") & "', "
sqlValues(13) = "'" & Request.Form("5") & "', "
...

sql = Join(sqlValues)

Is there any possible way I can avoid having to hard code
the above and have the page work out what it needs to do
dynamically?

try this:
http://www.aspfaq.com/show.asp?id=2036

--
Tom Kaminski IIS MVP
http://www.microsoft.com/windowsserver2003/community/centers/iis/
http://mvp.support.microsoft.com/
http://www.iisfaq.com/
http://www.iistoolshed.com/ - tools, scripts, and utilities for running IIS
http://www.tryiis.com
 
J

Jeff Cochran

I've create a simple survey using ASP. Its finished and
works, but one aspect of my coding is annoying me and I
cant figure out a better way of doing it.

There's a lot of sample ASP code out there to do surveys, take a look
at some of the methodology. Survey responses are not the easiest
things to code when you allow multiple types of questions, you may
find a canned package is cheap compared to your time.

Jeff
 
C

Colin Steadman

There's a lot of sample ASP code out there to do surveys, take a look
at some of the methodology.

I did try looking for some examples, but this project came from
no-where without warning and I was only given a day to sort it out. I
literally had to scrawl some ideas on a bit of paper and got cracking.
It was great fun though.

Survey responses are not the easiest
things to code when you allow multiple types of questions, you may
find a canned package is cheap compared to your time.

Jeff

I was fortunate that all the questions were to be answered in the same
way. If it has been a jumble of question types I wouldn't have had a
chance.

Colin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top