Click to See Complete Forum and Search --> : variable problem
Hi. I'm actually creating a language placement test.
Each page is composed of a bunch of exercises.
After clicking on the submit button (page1.asp), answers are automatically
corrected (page2.asp) and a score is given to the user.
So far, it’s pretty simple. Here’s a sample of the code which checks the
answers(page2.asp)
Page2.asp
<%
Dim answer1
Select case Request.Form ("1")
Case "yes"
answer1=1
Case "no"
answer1=0
End Select
Dim answer2
Select case Request.Form ("2")
Case "yes"
Answer2=1
Case "no"
Answer2=0
End Select
Dim total1
Total1=answer1+answer2
Response.Write total1
%>
Things get difficult (for me) when it comes to page3,4,5,6 …
In fact, the logic should be like:
page3.asp= total of “page1.asp”+ total of “page2.asp”
page4.asp= total of “page1.asp”+ total of “page2.asp” + total of “page3.asp” …..
My problem is that I don’t know how to call in page 3 a variable (like Dim total1)
I have set up in page 1. Instead, I’m asking the user in page 2 to re-enter his score
in a text-box form field (case) that I call in page 3. It looks like this:
<%
‘this is the total score for page1+page2
Dim totalpage1
Totalpage1=Request.Form ("case")
Dim totalpage2
Totalpage2=answer1+answer2+totalpage1
Response.Write totalpage2
%>
Well, it works fine but (1) it's annoying and (2) there's no integrity
at all as users can re-enter a fake score.
Does anyone have an idea how to simplify this procedure?
Something like having every single result stored in a buffer and being able to call
any variable anytime during the session.
Thanks in advance for your help.
khaki
06-18-2003, 12:50 PM
hi loic...
couldn't you just pass the values from page to page by populating hidden text boxes?
that way you don't sacrifice integrity... and the values are always available.
have I over-simplified the problem?
If so... let me know and I'll try to think about it from a different angle.
sometimes simple...
;) k
Hi Kakhi,
This definitely makes sense and much more simple. I was about to use a session object which would have required a lot of coding and I didn’t really want to go for that.
I guess the Html for hidden text boxes would be something like:
<INPUT TYPE="hidden" NAME=myHiddenElement>
As you know, I’m asking the user in page X to re-enter his score in a text-box form field that I call in page Y. If I’m using a hidden text box like you said, how could I have the score automatically transferred to this hidden box? I’m not sure my question is clear … if not, could you provide me with a short sample of code so I could work on it? I’m just trying to figure it out. Really appreciate your help.
Thks
Loic
Ribeyed
06-18-2003, 02:24 PM
hi,
can you post the code you have so far?
khaki
06-18-2003, 02:30 PM
hi again loic...
you could just write the form and the values in one swoop:
<%
response.write("<form name='page1'>")
response.write("<input type='hidden' name='answ1' value=" & answer1 & ">")
response.write("<input type='hidden' name='answ2' value=" & answer2 & ">")
response.write("<input type='hidden' name='tot1' value=" & total1 & ">")
response.write("</form>")
%>
(the values will be populated by your SELECT CASE statements)
will this work for you?
;) k
I'm going to give a shot to Kakhi's code. Ribeyed, let me gather togheter what I've got so far and I'll post it. This is really helpfull, thanks again.
Ok, I've selected 3 pages (I've got something like 60 pages)
Content is in French so feel free to contact me if you have any problem understanding (so far the code is concerned, the language shouldn't be a problem). I'm going to test Khaki's answer right now.
I guess the attachement didn't go through
Ribeyed
06-20-2003, 01:29 PM
hi loic,
sorry for not getting back sooner. I think i can help you out with this one. Looking at your pages test2.asp, test3.asp and test4.asp i can get a fair idea of what you are trying to do.
I have a few questions for you; do you want to hold onto all the answers for the 3 pages then correct them on test5.asp or do you want to correct the questions on each page before moving on to next set of questions?
Do you just want the score from each page to carry through to the last page then display the total score?
Do you want to show all the answers given at the end along with the score?
how are you validating the questions?
khaki
06-20-2003, 01:50 PM
oh....
I gotta be honest...
I didn't even realize that this wasn't resolved :rolleyes:
so Loic... the method that I suggested doesn't work for your particular needs?
(another confession: I rarely open the ZIP files :eek: I just have too darn many of them that I haven't even gotten around to deleting yet :rolleyes: so... no... I never even looked :( )
well... you're in capable hands with Dave... but...
I hate to bail-out on a half-finished thread.
Anything that I need to know about what troubles you are still having?
I'm still willing to help if I can :)
give us an update on the status of this...
;) k
Hi Khaki,
I've finaly made it using a session objects:
<%Session("myscore")=total%>
that I can call anytime I want :
<%Dim total
total=Session("myscore")%>
One single line made my life much easier :) !!!
Thanks again for your help, your answer allowed me to look at this issue from another angle and finally found out.
cya around
Loďc
HI Ribeyed
sorry I didn't see your had answered back. Thanks again. Even if my problem is now solved, I would be curious to see how you made it.
-------------------------
do you want to hold onto all the answers for the 3 pages then correct them on test5.asp or do you want to correct the questions on each page before moving on to next set of questions?
I wanted to correct the questions on each page before moving on to next set
-------------------------
Do you just want the score from each page to carry through to the last page then display the total score?
---------------
Do you want to show all the answers given at the end along with the score?
that's it. Plus I want the user to see the details of his score. Something like:
Grammar:x/5
Phonetics:x/5
Comprehension:x/5
Total: Y/20
----------------
how are you validating the questions?
Yes I am
---------------
Using a session object, I'm now able to have a table created at the end of the test which contains all the details . It works perfectly. Being able to do this was pretty much the cornerstone of the project I'm working on, so I feel much better now. Thanks again for your help.
Loďc
khaki
06-20-2003, 02:59 PM
hi Loic...
just as an FYI (and not that it speaks specifically to your own situation)...
but here is an article from my boys (the4GuysFromRolla) concerning Session variables.
http://www.4guysfromrolla.com/webtech/faq/Advanced/faq4.shtml
I admit that I am a Session Variables scaredy-cat... and I have conditioned myself to not use them.
But I do realize that they can be used to good effect under the right circumstances.
It's a good article (pretty short too :) ) if you want a little insight into the perils of Session Variables (and why I don't suggest them as solutions).
But anyway... as long as you got your pages working well.... I'm glad that you found the solution that works for you :)
;) k