| Author |
Topic  |
|
|
ILLHILL
Junior Member
 
Netherlands
341 Posts |
Posted - 05 June 2010 : 09:29:16
|
Hi everybody, I'm currently writing a piece of code to compare the answers of 10 multiple questions with the answers. The optional answers to the questions have values of w, x, y and z. These then get compared to an array, for example:
x,x,x,x,x,x,x,x,x,x
On the quiz page the values get send to the results page.
However, when all 10 answers are correct, the outcome is 9 out of 10 points. The answer from the first question is ignored. Here's the code:
MyArray2 = Split(answer_string, ",", -1, 1)
answer1 = MyArray2(0) answer2 = MyArray2(1) answer3 = MyArray2(2) answer4 = MyArray2(3) answer5 = MyArray2(4) answer6 = MyArray2(5) answer7 = MyArray2(6) answer8 = MyArray2(7) answer9 = MyArray2(8) answer10 = MyArray2(9)
quizscore_final = 0
if q1 = answer1 then quizscore_final = quizscore_final + 1 end if
if q2 = answer2 then quizscore_final = quizscore_final + 1 end if
if q3 = answer3 then quizscore_final = quizscore_final + 1 end if
if q4 = answer4 then quizscore_final = quizscore_final + 1 end if
if q5 = answer5 then quizscore_final = quizscore_final + 1 end if
if q6 = answer6 then quizscore_final = quizscore_final + 1 end if
if q7 = answer7 then quizscore_final = quizscore_final + 1 end if
if q8 = answer8 then quizscore_final = quizscore_final + 1 end if
if q9 = answer9 then quizscore_final = quizscore_final + 1 end if
if q10 = answer10 then quizscore_final = quizscore_final + 1 end if
I'm not that familiar with arrays, but is there any reason why the first question answer is not correctly calculated?
I have tried "response.write" to display the selected answers as well as the given answers and these get listed correctly. However, the score result has a maximum of 9 max instead of 10.
Anybody has any suggestions?
With kind regards,
Dominic
****Edit**** I noticed that the in predetermined answers that get pulled from the array, a space is added before the variable of answer1. This seems to cause the issue, as "X" is not equal to " X".
answer1 = X answer2 =X answer3 =X answer4 =X
Why is this space added when the array is split?
|
CLPPR.com - All The News Only Seconds Away |
Edited by - ILLHILL on 05 June 2010 09:58:12 |
|
|
bobdsw
New Member

United States
62 Posts |
Posted - 05 June 2010 : 09:56:43
|
Try remming out the If statement (q1 = answer1) for the first element in the array and see if it's added.
If it is then the problem is the If statement itself and you'll need to check either the values of q1 and answer1 and verify they are equal. |
Phoenix! - Ful site integration, CSS driven & XHTML compliant, MooTools, TinyMCE editor for posts & custom content management, , Visual Theme Designer, custom menus & pages, member galleries with ASP JPeg and ASPResize, ASP WordPress style Blog, web friends, FaceBook, Twitter & other social-sharing integration, ReCaptcha & Anti-Spam Registration...and much more.
|
 |
|
|
ILLHILL
Junior Member
 
Netherlands
341 Posts |
Posted - 05 June 2010 : 10:01:20
|
Hi bobdsw, Thanks for your reply. It seems you posted it at the moment I was editing my post. A space is added to the first answer when the array is split. I have no idea why this space is added, but "X" is logically not equal to " X", so that seems to be why the first question is answered incorrect according to the script.
Any idea why this space is added to the array?
array string = "X,X,X,X,X,X,X,X,X,X," there's no space in front of the first X.
Greets & thanks, Dominic |
 |
|
|
HuwR
Forum Admin
    
United Kingdom
20611 Posts |
|
|
ILLHILL
Junior Member
 
Netherlands
341 Posts |
Posted - 05 June 2010 : 10:26:58
|
Hi HuwR, thanks for the reply.
Unfortunately Trim and Replace (replacing " " with "") have not worked yet for either the string as a whole or the variable. I will continue trying though.
Thanks again.
Greets, Dominic |
CLPPR.com - All The News Only Seconds Away |
 |
|
|
bobdsw
New Member

United States
62 Posts |
Posted - 05 June 2010 : 10:58:28
|
When you look at myarray2, before you split it, does the space exist?
Trim should work. I would make sure you're running it on both the q and the answer for each. You may also want to try running lcase or ucase on both as well, just in case. |
Phoenix! - Ful site integration, CSS driven & XHTML compliant, MooTools, TinyMCE editor for posts & custom content management, , Visual Theme Designer, custom menus & pages, member galleries with ASP JPeg and ASPResize, ASP WordPress style Blog, web friends, FaceBook, Twitter & other social-sharing integration, ReCaptcha & Anti-Spam Registration...and much more.
|
 |
|
|
Carefree
Advanced Member
    
Philippines
4224 Posts |
Posted - 05 June 2010 : 12:01:29
|
Well, if you know the problem is with answer 1 having a leading space, it's a simple thing to resolve.
quote:
if q1 = answer1 then
Change to:
if q1 = right(answer1,1) then
or, if the answer can have more than one character:
if q1 = mid(answer1,2) then |
Edited by - Carefree on 05 June 2010 12:02:33 |
 |
|
| |
Topic  |
|
|
|