-
April 7th, 2016, 06:02 AM
#1
Help!! Multi-Choice Quiz
okay hi there, im a bit of a newbie when it comes to coding and i was wondering if you guys could give me some help; so im wanting to create a multiple choice quiz, this is what i have so far;
Code:
Public Class Form1
Dim questions(2, 5) As String
Dim answers(2) As String
Dim quesNum As Integer
Private Sub GetQuestions()
questions = New String(,) {{"What is the correct spelling of this word?", "Mas", "Masse", "Mass", "Mase", "Mass"}, _
{"What is the correct spelling of this word?", "Base", "Bass", "Basse", "Bayse", "Base"}, _
{"What is the correct spelling of this word?", "Datta", "Data", "Dayta", "Daiter", "Data"}, _
{"What is the correct spelling of this word?", "Gene", "Jeine", "Geane", "Jean", "Gene"}, _
{"What is the correct spelling of this word?", "Gaes", "Gase", "Gass", "Gas", "Gas"}, _
{"What is the correct spelling of this word?", "Laws", "Lawz", "Lawes", "Lawse", "Laws"}, _
{"What is the correct spelling of this word?", "Soilid", "Sollid", "Soled", "Solid", "Solid"}, _
{"What is the correct spelling of this word?", "Tishew", "Tisshue", "Tissue", "Tishue", "Tissue"}, _
{"What is the correct spelling of this word?", "Beaker", "Beacker", "Beeker", "Beecker", "Beaker"}, _
{"What is the correct spelling of this word?", "Acohol", "Alcohol", "Ackohol", "Alckohol", "Alcohol"}, _
{"What is the correct spelling of this word?", "Liquid", "Licquid", "Licwuid", "Liqwuid", "Liquid"}, _
{"What is the correct spelling of this word?", "Ionnic", "Ionic", "Eyeonic", "Ionick", "Ionic"}, _
{"What is the correct spelling of this word?", "Meteaor", "Meateor", "Meteor", "Meeteor", "Meteor"}, _
{"What is the correct spelling of this word?", "Zigote", "Zygotte", "Zigotte", "Zygote", "Zygote"}, _
{"What is the correct spelling of this word?", "Allele", "Alele", "Alelle", "Allelle", "Allele"}, _
{"What is the correct spelling of this word?", "Assteroid", "Asteroyd", "Asteroid", "Astteroid", "Asteroid"}, _
{"What is the correct spelling of this word?", "Gallaxy", "Galaxy", "Galaxye", "Galaxey", "Galaxy"}, _
{"What is the correct spelling of this word?", "Velosity", "Velocitey", "Velocity", "Vellocity", "Velocity"}, _
{"What is the correct spelling of this word?", "Viabillity", "Viabbility", "Viablity", "Viability", "Viability"}, _
{"What is the correct spelling of this word?", "Viscosity", "Visckosity", "Visscosity", "Viscossity", "Viscosity"}, _
{"What is the correct spelling of this word?", "Gravitty", "Gravitey", "Gravity", "Gravittey", "Gravity"}, _
{"What is the correct spelling of this word?", "Issotope", "Isotope", "Isotoppe", "Iceotope", "Isotope"}, _
{"What is the correct spelling of this word?", "Prediction", "Predicttion", "Preddiction", "Preadiction", "Prediction"}, _
{"What is the correct spelling of this word?", "Allkali", "Alkalli", "Alckali", "Alkali", "Alkali"}, _
{"What is the correct spelling of this word?", "Genetic", "Gennetic", "Genettic", "Genetick", "Genetic"}, _
{"What is the correct spelling of this word?", "Teeory", "Theorey", "Theorry", "Theory", "Theory"}, _
{"What is the correct spelling of this word?", "Kinetic", "Kinettic", "Kinnetic", "Kinetick", "Kinetic"}, _
{"What is the correct spelling of this word?", "Fushion", "Fussion", "Fushion", "Fusion", "Fusion"}, _
{"What is the correct spelling of this word?", "Eclipse", "Ecklipse", "Eclippse", "Ecllipse", "Eclipse"}, _
{"What is the correct spelling of this word?", "Acuracy", "Accuracey", "Accurasey", "Acuracey", "Accuracy"}, _
{"What is the correct spelling of this word?", "Climatte", "Clymate", "Clymatte", "Climate", "Climate"}, _
{"What is the correct spelling of this word?", "Biolgy", "Biollogy", "Biology", "Biologey", "Biology"}, _
{"What is the correct spelling of this word?", "Nucklear", "Nukelear", "Nukeleer", "Nuclear", "Nuclear"}, _
{"What is the correct spelling of this word?", "Fision", "Fichon", "Fisshon", "Fishon", "Fission"}, _
{"What is the correct spelling of this word?", "Ellement", "Element", "Elementt", "Ellmentt", "Element"}, _
{"What is the correct spelling of this word?", "Fisics", "Phsics", "Physics", "Physices", "Physics"}, _
{"What is the correct spelling of this word?", "Vacine", "Vaccinne", "Vaccinne", "Vaccine", "Vaccine"}, _
{"What is the correct spelling of this word?", "Control", "Conntrol", "Controll", "Controle", "Control"}, _
{"What is the correct spelling of this word?", "Mytosis", "Mytossis", "Mitossis", "Mitosis", "Mitosis"}, _
{"What is the correct spelling of this word?", "Conducttion", "Conduction", "Conductionn", "Conductione", "Conduction"}, _
{"What is the correct spelling of this word?", "Reaction", "Reacttion", "Reakshon", "Reacktion", "Reaction"}, _
{"What is the correct spelling of this word?", "Magnetick", "Magnetic", "Magetice", "Magnettic", "Magnetic"}, _
{"What is the correct spelling of this word?", "Chemisstry", "Chemistrey", "Chemistry", "Chemisttry", "Chemistry"}, _
{"What is the correct spelling of this word?", "Patthogen", "Pathogene", "Pathogenn", "Pathogen", "Pathogen"}, _
{"What is the correct spelling of this word?", "Precision", "Precishon", "Precission", "Precisione", "Precision"}, _
{"What is the correct spelling of this word?", "Dependent", "Dapendent", "Dapendant", "Dependant", "Dependant"}, _
{"What is the correct spelling of this word?", "Variable", "Viable", "Varriable", "Variabel", "Variable"}, _
{"What is the correct spelling of this word?", "Boisphere", "Biosphere", "Biossfere", "Byosphere", "Biosphere"}, _
{"What is the correct spelling of this word?", "Resourse", "Reasource", "Resource", "Reesource", "Resource"}, _
{"What is the correct spelling of this word?", "Lisosome", "Lysosomme", "Lisosomme", "Lysosome", "Lysosome"}, _
{"What is the correct spelling of this word?", "Eletricity", "Electricitty", "Electricity", "Electtricity", "Electricity"}, _
{"What is the correct spelling of this word?", "Replication", "Repplication", "Replicattion", "Repplicattion", "Replication"}, _
{"What is the correct spelling of this word?", "Technology", "Tecknology", "Technollogy", "Technologey", "Technology"}, _
{"What is the correct spelling of this word?", "Microsccope", "Miscroscope", "Microscope", "Mikeroscope", "Microscope"}, _
{"What is the correct spelling of this word?", "Comppound", "Compound", "Compounde", "Compaoud", "Compound"}, _
{"What is the correct spelling of this word?", "Homologous", "Hommologus", "Homolougus", "Homolougous", "Homologous"}, _
{"What is the correct spelling of this word?", "Evoluttion", "Evelution", "Evolution", "Evilution", "Evolution"}, _
{"What is the correct spelling of this word?", "Wait", "Weight", "Wayte", "Waite", "Weight"}, _
{"What is the correct spelling of this word?", "Difusion", "Diffusione", "Difusione", "Diffusion", "Diffusion"}, _
{"What is the correct spelling of this word?", "Difraction", "Diffreacttion", "Diffraction", "Difracione", "Diffraction"}, _
{"What is the correct spelling of this word?", "Independent", "Independant", "Indapendent", "Indapendant", "Independent"}, _
{"What is the correct spelling of this word?", "Tempriture", "Temprature", "Temperature", "Temperatur", "Temperature"}, _
{"What is the correct spelling of this word?", "Segregashon", "Segregation", "Segretgattion", "Segragation", "Segregation"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Homozygous"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Uncertainty"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Momentum"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Geosphere"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Reproduction"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Respiration"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Longitude"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Astronomical"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Acceleration"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Laboratory"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Experiment"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Ionisation"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Molecular"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Exocytosis"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Catalyst"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Celcius"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Astronomy"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Multi-Cellular"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Constellation"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Cytoskeleton"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Organelles"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Electrolyte"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Ionising"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Chromosome"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Hypothesis"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Palaeontology"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Hypothalamus"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Heterozygous"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Gravitational"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Photosynthesis"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Polymerisation"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Carbohydrates"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Neutralisation"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Mitochondria"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Equilibrium"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Meteorologist"}, _
{"What is the correct spelling of this word?", "5", "6", "7", "", "Fahrenheit"}}
End Sub
Private Sub MarkTest()
Dim grade As Integer = 0
For i = 0 To 2
If answers(i) = questions(i, 4) Then
grade += 1
End If
Next
Label1.Text = "Test finished!"
Label2.Text = "You scored " & grade & " out of " & answers.Length & "!"
RadioButton1.Enabled = False
RadioButton2.Enabled = False
RadioButton3.Enabled = False
RadioButton4.Enabled = False
Button1.Enabled = False
Button2.Enabled = False
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Me.Text = "My Multiple Choice Quiz!"
GetQuestions()
quesNum = 1
Label1.Text = "Question " & quesNum & " of " & answers.Length
Label2.Text = questions(0, 0)
Button1.Text = "Previous"
Button2.Text = "Next"
RadioButton1.Text = questions(0, 1)
RadioButton2.Text = questions(0, 2)
RadioButton3.Text = questions(0, 3)
RadioButton4.Text = questions(0, 4)
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
If quesNum > 1 Then
quesNum -= 1
Label1.Text = "Question " & quesNum & " of 3"
Label2.Text = questions(quesNum - 1, 0)
RadioButton1.Text = questions(quesNum - 1, 1)
RadioButton2.Text = questions(quesNum - 1, 2)
RadioButton3.Text = questions(quesNum - 1, 3)
RadioButton4.Text = questions(quesNum - 1, 4)
If Button2.Text = "Submit" Then
Button2.Text = "Next"
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
If RadioButton1.Checked = True Then
answers(quesNum - 1) = RadioButton1.Text
ElseIf RadioButton2.Checked = True Then
answers(quesNum - 1) = RadioButton2.Text
ElseIf RadioButton3.Checked = True Then
answers(quesNum - 1) = RadioButton3.Text
ElseIf RadioButton4.Checked = True Then
answers(quesNum - 1) = RadioButton4.Text
End If
RadioButton1.Focus()
If quesNum < 3 Then
quesNum += 1
Label1.Text = "Question " & quesNum & " of " & answers.Length
Label2.Text = questions(quesNum - 1, 0)
RadioButton1.Text = questions(quesNum - 1, 1)
RadioButton2.Text = questions(quesNum - 1, 2)
RadioButton3.Text = questions(quesNum - 1, 3)
RadioButton3.Text = questions(quesNum - 1, 4)
If quesNum = 3 Then
Button2.Text = "Submit"
End If
Else
MarkTest()
End If
End Sub
End Class
[/CODE]
now the numbers in "" is just where i havent completely finished the questions yet.
there are a few problems with this which i need addressed before i continue any further;
1) when clicking on a correct answer it still says its wrong
2) i want 10 levels, 3 questions per level which i want to be randomised; questions 1-10 for level 1, 11-20 for level 20 etc.
thanks
-
April 9th, 2016, 09:40 PM
#2
Re: Help!! Multi-Choice Quiz
Well I did not study the code you posted there, not enough time for that right now but from a quick glance my first suggestion would be to use an external source for the questions and answers rather than hard coding them into the exe. Using a text file or a database of some sort would give you flexibility to change the questions, create multiple quizzes and such without ever changing the exe which of course makes for a better program that is more flexible and you do not end up with a 100 lines of hard coded text in your code window.
Using a DB would be my choice and would require very little code to make it very flexible where you could have multiple different quizzes and variable number of questions or whatever the need may be.
Always use [code][/code] tags when posting code.
-
April 10th, 2016, 03:51 PM
#3
Re: Help!! Multi-Choice Quiz
Thanks for your reply
How would I do that?
-
April 13th, 2016, 08:18 PM
#4
Re: Help!! Multi-Choice Quiz
Well you could simply put the questions and the related choices in a table along with the correct choice much like you have done in your array except I would use the field index number of the correct answer rather than typing it out. You could also include a quiz ID field so that the table could hold more than one quiz. You could easily add a method for a user to create a new quiz, edit existing quiz or whatever you like.
As for how to handle it beyond that I would need you to ask a more specific question as I have no idea what your level is nor what part you have an issue with.
Always use [code][/code] tags when posting code.
-
April 14th, 2016, 02:07 AM
#5
Re: Help!! Multi-Choice Quiz
Okay thanks for that, how would I use a field index number? And the problem is; there is a screen with 10 levels, when a person clicks on level 1 I want 3 questions after the other from the questions 1-10 after that the person can click on next level or scoreboard (how would I do this also) thanks.
-
April 14th, 2016, 10:54 PM
#6
Re: Help!! Multi-Choice Quiz
Well if you are working with a data base you would be reading from a dataset which is like a 2d array Rows and columns. So each row has all the info you need for a given question. Including the column number or index of the correct answer. Using your option buttons you simply need to check and see if the one they selected is in the right position.
I am more familiar with VB6 and in VB6 I would be using recordset for the data and a control array for my option/radio buttons
so my code might look something like
Code:
lblQuestion.Caption=rs(0).value ' the first field in my recordset which of course is very similar to a dataset in vb.net
For X=1 to 4
optAnswer(x).caption=rs(x).Value ' places the four answers across the 4 option buttons
Next
Now how you deal with the answer depends on if you want to do one at a time or if you want to display multiples. If you need to do multiples then you may need to store the correct answer value either in perhaps the tag property of your question label or you may want to use an array or a list (of integer)
Lets assume you used the tag so after the code above you may have something like
Code:
lblQuestion.Tag=rs(5).Value
In your button click event you would check to see if the right option was selected.
Following along that same Vb6 code it may look something like
Code:
If optAnswer(val(lblquestion.tag)) then
'Correct
Else
' Not Correct
End IF
Now naturally this would be a little different in VB.Net as it does not directly support control arrays and it does not use the caption property but perhaps it will be enough to give you and idea.
If you are doing multiple questions then you simply move to the next row in your recordset/dataset and do the same thing
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|