PDA

Click to See Complete Forum and Search --> : Multiple Choice Testing Program


Sal
Apr 27th, 2000, 03:01 PM
Hello,

I am a newbie and am having a bit of difficulty with a database issue. I created a database in Microsoft Access and it contains a list of Questions with multiple choice answers. I setup a database in Visual Basic with labels for the questions and answers.

My problem is how to randomly setup the correct answer so that - for example answer (a) will not always be the correct answer. In my database the correct answer is in a field titled answer. So I need the correct answer to be in a different place as the user goes to the next question.

I used data1 and labels. In the labels' datafield property I chose the appropriate datafield. Example - The question label's datafield is obviously "question" (from access). But the other four labels would all remain the same as I clicked through to the next recordset, ie. answer A would always be the correct answer. I could go into access and change the order of answers. But, later I would not be able to randomize the answers, so that the user wouldn't remember the order of questions.

Thank you for any help.

Apr 27th, 2000, 10:22 PM
This may or may not be the "right" way to do it, but if I sat down to do this I wouldn't bind the labels to the data fields.

The algorythm would look like this:

1. Create a data structure (TYPE) that contains
- A possible answer as string
- Is this answer correct as boolean
- Has this been placed on the screen as boolen
2. Create an array of objects of the above type (four elements for 4 answers per question, etc)
3. Read each answer into the array setting the isPlaced boolean to FALSE for each and the isCorrect boolean to TRUE as appropriate
4. For Each label, randomly choose an element of this array where isPlaced is FALSE. Set label.caption to the string, and set isPlaced to True. Set the Tag of the label to the value of isCorrect.
5. When the user clicks the label, just check the Tag to see if its correct or not.


This method will give you a lot of flexibility as you change the program (ie. two answers could be correct for one question, etc.)

Hope that helps

-John

Sal
Apr 27th, 2000, 11:22 PM
On the run with the baby...thanks for the tip. When I get home I will try it.

Sal Crocker

Sal
Apr 28th, 2000, 09:42 AM
Anyone else have an approach to this? I bound the labels to the datafields and was going to try to individually change each question's multiple choice options by using select case.

Excerpt:
Select Case data1.recordset 'I am trying to use the access
'database ID number as a value
'but don't know how to do it
'is this possible?
case = 1
lblAnswerA.DataField = "multi-1"
lblAnswerB.DataField = "multi-3"
lblAnswerC.DataField = "multi-2"
lblAnswerD.DataField = "CorrectAnswer"
case = 2
lblAnswerA.DataField = "multi-1"
lblAnswerB.DataField = "multi-3"
lblAnswerC.DataField = "multi-2"
lblAnswerD.DataField = "CorrectAnswer"

More: The database has one question and four multiple choice options stored . I named them mult-1, multi-2, multi-3, and answer(answer is the correct choice). It seems to me that I ought to be able to arrange these in different places as the user selects the next question the multiple choice answers are in a different place. Again, so that answer b for example is not always the correct answer. I felt like if I used selectcase where as the case is the database ID number, then I could change the datafield property of the label which contains the choices.

John gave one approach, but before the newbie here tries it,(which I'm not sure I can figure out how to implement), I would like to know if my approach is possible.

Thanks,
Sal

look
Mar 30th, 2002, 11:27 PM
i have read your thread in Multiple choice question , i have the same problem in randomizing the answers but i don't read form a database i read form a text file and i want to randomize the question and its own answers.. if you have an idea please help

Jethro
Apr 1st, 2002, 02:57 AM
On.ly hae approx five minutes...so am hammering on this

Don't data bind...sucks....see Beacons tutorial on programmatic connection of database above


1. Store in db Question, five answers, make the first the correct one.

2. Screen refresh on each question, to go to next etc.

3. Use rnd() function to generate slot to put correct answer in.

4. Populate text boxes with answers, the correct one going in the rnd numbered one, look up the function to get it to work, and store the generated rnd correct number.

5. Either right or wrong, but am thinking you only want to know if correct or not correct...keep tally.



Put question in label right...


Gotta go, if need expansion on answer will provide tomorrow.. sorry charging out of the room now......

look
Apr 2nd, 2002, 12:32 AM
Jethro you've said "Store in db Question" but if you read my question i'm using a text file not DB..AND I NEED expansion on answer AND tomorrow HAS ARRAIVED;);)

Jethro
Apr 2nd, 2002, 01:36 AM
Originally posted by look
Jethro you've said "Store in db Question" but if you read my question i'm using a text file not DB..AND I NEED expansion on answer AND tomorrow HAS ARRAIVED;);)

Er....answer was for the first post... just about to walk out of the office, but will start answering tonite when l get home....

Ok you know how to connect the text file right?

Will think on it....


But am sort of thinking something like, text file construct

"Q 0001Does Justin Use Dells"
"A10001Yes"
"A20001No"
"A30001Who's Justin"
"A40001What's a Dell"
"R 0001A1"


Sort of Question, then four alternative answers, and then the right answer. Re-iterate a loop to extract each question, and dipslay each time a window is shown....

Jethro
Apr 2nd, 2002, 04:11 AM
Okay Look here's a project showing what you want...


Extract and load anywhere and run...


Based on text line extract of Question,Ans1,Ans2,Ans3,Ans4,CorrectAns


Hope it helps..... er see attachment zip of vb5 project;)

Jethro
Apr 2nd, 2002, 05:00 AM
Should have added this is a quick and dirty example, which probably could be improved....

Sample .txt file included...