11 Replies - 9673 Views - Last Post: 15 November 2010 - 06:54 PM Rate Topic: -----

#1 samuel17  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Making a quiz

Posted 15 November 2010 - 03:04 PM

Hi all,
Im just wondering if anyone has ever made a quiz in VB before. What im thinking is to have a question, then between 2-4 answers, and depending on the answer a point value gets assigned to a varible, but then when that one question is answered you can click a button that moves to a next page type of thing with a new question on it. This is just going to be a fun little thing for my psychology class, and is totally not needed, but i figured it would be fun. I think i could probably figure most of this out but when it comes to switching to a different question im not sure how i would do that. Hoping someone can help me with this, i check around on the internet and didnt find anything quite the way i was hoping to do this, i also want it to be just VB based, not needing an external database or anything like that.

Thanks,
Sam

Is This A Good Question/Topic? 0
  • +

Replies To: Making a quiz

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9195
  • View blog
  • Posts: 34,517
  • Joined: 12-June 08

Re: Making a quiz

Posted 15 November 2010 - 03:26 PM

Yeah this is a pretty straight forward design.

You need something to 'enter in' the questions and options, right? Also a way to mark the right answer. If you don't want a database then you could store these with an XML file.

You need to determine how you want the transition to occur. Is it the first time they click a radio button or do they have to click a radio button then hit 'answer' or 'next'... or have multiple questions available and a 'next' button. The button idea makes it so you can validate your input. You know - make sure something is there.

Off the top of my head I easily see this being a class that has a few strings and a few integers.

class Question
private string sQuestion = ""
private string sAnswer1 = ""
private string sAnswer2 = ""
private string sAnswer3 = ""
private int lRightAnswer = 0
private int lAnsweredSelection = 0

properties to expose those

a constructor to default those values
'-- true if lRightAnswer = lAnsweredSelection
'-- false other wise.
public bool RightChoice


Basically you would create a list<of type Question>... load the answers and questions from the XML and insert each into the collection.

Each time a question is loaded up from the list collection (keep track of the current one) fill in the question label and the three radio button texts. When the 'next' or 'answer' button is clicked make sure a radio button is clicked and then record which one was clicked into the current list collection's object.

Then clear the radio buttons and reload the questions.

At the end go through and see if each question was answered or not!

A bit of work but pretty straight forward. Hell I might do this just for kicks!
Was This Post Helpful? 0
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: Making a quiz

Posted 15 November 2010 - 03:26 PM

Do a search here on DIC in the VB.NET forum using the keyword "quiz" and you will see we have helped with many quiz projects in VB.NET. It is project that is often requested here on the forums.


Good luck with the project. :)

This post has been edited by Martyr2: 15 November 2010 - 03:27 PM

Was This Post Helpful? 0
  • +
  • -

#4 samuel17  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Re: Making a quiz

Posted 15 November 2010 - 03:36 PM

modi123_1,
Is an XML needed? My thought was just to hand write the questions in there using labels and then have radio buttons A,B,C,D, If radio button A is selected, then add for example, + 5 to the sum variable, which i believe would have to be a static variable so it doesnt change, but then possibly refresh the page and have a new question, but again having the varible sum stay the same? Am i making this seem like it should be way to easy? haha
Martyr2,
You have helped me a lot, didnt know ya do VB too. I will check other forums right after i go back and check on my java forum haha

Thank you both,
Sam
Was This Post Helpful? 0
  • +
  • -

#5 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: Making a quiz

Posted 15 November 2010 - 03:44 PM

* Martyr2 points to the left at all the languages where it reads "Expert In".

I mentor 27 different main and sub forums here. One minute I am spewing VB, another time I am in Java and after that could be doing Python, PHP or C/C++. Yeah, I have no life. But I guess that is good for people who are learning. ;)
Was This Post Helpful? 0
  • +
  • -

#6 samuel17  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Re: Making a quiz

Posted 15 November 2010 - 03:50 PM

haha whoops, i guess i missed that :P Well you having no life helps me greatly, you have helped me a lot and i appreciate it, especially the explainations. Thanks :)

Sam
Was This Post Helpful? 0
  • +
  • -

#7 samuel17  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Re: Making a quiz

Posted 15 November 2010 - 04:31 PM

hey Martyr2,
I was reading one of your other posts on someone looking to make a quiz and they had the questions and answers in a text file and using a delimiter, read them into arrays. This was a short thread i was reading and didnt get too much help from it, but would it really be necissary to read it into arrays from a text file or could you just make an array, have the array put the question in a label on the top and the answer in a radio button label under that and have those correspond to the answer and depending on that answer have a value assigned such as 3 that will cause the score to increase by 3 if that answer is selected. I want all of the answers to have point values, the quiz, being for psychology is gonna be something like less then 3 points, you are mentally insane and so on haha. Another thread i was reading, some guy just had as many forms as questions, and then have a question answered using radio buttons, it would add points to the score, and then when the next button was clicked it linked to a different form with a different question. That to me seems logical, but most VB programs i have ever done have been based on one form so adding more then one form kinda makes me wonder about it. I would prefer the second option, hand type question in a label and radio button A,B,C... hold values such as 3,4,5... and then next question. What are your thoughts about that? Man it really feels good to get to talk VB to someone haha :)

Thanks,
Sam
Was This Post Helpful? 0
  • +
  • -

#8 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: Making a quiz

Posted 15 November 2010 - 04:38 PM

There are many ways to make the quiz setup. Some use an array like that, some read the question and answers into variables and display those, some do exactly as you said and put it into a label and radio buttons and depending on the one they chose they get points assigned. All these options, and many others, are variations of the quiz project.

You are the designer and you choose how it will look and behave. The other threads were meant to spark ideas and give you options on how you can implement it. Sounds like you are well on your way to devising a solution that will certainly work. Play with it and if you continue to have troubles, show us what you have already come up with and we can propose additional/alternative tips. :)
Was This Post Helpful? 0
  • +
  • -

#9 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Making a quiz

Posted 15 November 2010 - 04:44 PM

You CAN do it all in code it would just be a lot of redundancy. Using a textfile would reduce the code a lot.

From
While there are still question in the file
Read In Question
Fill In Question Label
Fill In Option buttons(denoting correct answer)
Increment variable when correct answer chosen
End While

to
Fill in question label
Fill in Option Buttons
Increment variable when correct answer chosen

Fill in question label
Fill in Option Buttons
Increment variable when correct answer chosen

... repeat for each one.

The different methods explained above are good for two three things. 1, they reduce your code thus making it less prone to bugs and 2, they are a good exercise to learn different methods of doing these types of things and 3, they allow you to change the textfile to either add more questions or change them completely without re-writing your code.

There are a lot of people that struggle to even come up with an idea that will help them learn a new feature of the language so keep that in mind when deciding if you want this to advance your knowledge of the language as you're developing it.

Either way, a Label and a number of option buttons along with a next button will most likely be all you need to display to the user. Just keep changing the labels and option button texts with the new question/possible answers.

EDITED as I realized a 3rd reason for using the above suggestions.

This post has been edited by CharlieMay: 15 November 2010 - 04:47 PM

Was This Post Helpful? 0
  • +
  • -

#10 samuel17  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Re: Making a quiz

Posted 15 November 2010 - 04:44 PM

Thanks Martyr2, VB is a little bit more my thing than java, I will try the multi form method, im not 100% on how i am going to work it all out but i guess i will just start and see what happens. Im already thinking on where my problems may be, but i will give it a shot and let you and the rest of the community know how it goes, this will be over the next few days so if im not back here tomorrow i didnt abondon anyone who is watching this thread :)

Thanks,
Sam
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9195
  • View blog
  • Posts: 34,517
  • Joined: 12-June 08

Re: Making a quiz

Posted 15 November 2010 - 06:44 PM

View Postsamuel17, on 15 November 2010 - 04:36 PM, said:

modi123_1,
Is an XML needed? My thought was just to hand write the questions in there using labels and then have radio buttons A,B,C,D, If radio button A is selected, then add for example, + 5 to the sum variable, which i believe would have to be a static variable so it doesnt change, but then possibly refresh the page and have a new question, but again having the varible sum stay the same? Am i making this seem like it should be way to easy? haha
Martyr2,
You have helped me a lot, didnt know ya do VB too. I will check other forums right after i go back and check on my java forum haha

Thank you both,
Sam


Wow this topic got far whilst I was out having dinner. God who says whilst anymore? I must be Team Edward for my ye old English.

Anyways.. the reason I suggested XML was for storage. Sure I guess you could hard code everything... but that hurts my head for the inefficiency.

Regarding the point totals - a quick modification of my class could easily take that into account. Heh.. gotta love your class based solutions.

Regarding the 'refresh page' you wouldn't really be "refreshing" anything - just reassigning text on the radio buttons and labels, right? So yes your variables need not go away.
Was This Post Helpful? 0
  • +
  • -

#12 samuel17  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Re: Making a quiz

Posted 15 November 2010 - 06:54 PM

Anything i need to know about passing variables to and from different forms? I just did 3 forms and decided to give it a test. My first form is the main form that i gave any point value for. I declared a value of 4 for a radio button labeled yes, which i select, and then on a final form i have a label that is suppose to display the sum variable number. I have a public variable "sum" on the question 1 form code and on the final form i have label.text = question1.sum but when i run it the result is "0". It could be my calculations but i thought it was rather straight forward, unless its how i passed the variable? Just thought id throw it out there, i looked online and seen thats how to pass variables. I will keep playing. Thanks for everyones help in my little fun test here.

Sam
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1