Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

Four Columns in a DataTable need to be randomly assigned to four labels VB.NET

Hi,

My problem is probably really simple and is as follows.

I have a data table full of questions.
They are in the following columns: ID, Question, CorrectAnswer, Incorrect1, Incorrect2, Incorrect3

It is for a multiple choice quiz.

I have four labels in a form: lblQ1, lblQ2, etc.

I need to randomly assign the location of my correct answer and then my incorrect answers.

I then need to be able to validate if the selected answer was the correct answer.

Any help much appreciated.

thanks,
Oli
0
olifarago
Asked:
olifarago
1 Solution
 
BTosonCommented:
This is somethign quick and dirty that I just knocked up that may give you a few ideas.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
	Dim Controls() As Control = {lblQ1, lblQ2, lblQ3, lblQ4}
	Dim Answers() As String = {CorrectAnswer, Incorrect1, Incorrect2, Incorrect3}
	Dim MuddledControls As New Generic.SortedList(Of Guid, Control)(Controls.Count)
	For Each Control In Controls
		 MuddledControls.Add(Guid.NewGuid, Control)
	Next
	For I As Integer = 0 To Answers.Count - 1
		 Dim Control = MuddledControls.Values(I)
		 Control.Text = Answers(I)
		 Control.Tag = If(I = 0, "Correct", "Incorrect")
	Next I
End Sub
 
Private Sub CheckAnswer(ByVal sender As Control, ByVal e As System.EventArgs) Handles lblQ1.Click, lblQ2.Click, lblQ3.Click, lblQ4.Click
	If sender.Tag = "Correct" Then
		MsgBox("Correct Answer!")
	Else
		MsgBox("Incorrect Answer!")
	End If
End Sub

Open in new window

0
 
olifaragoAuthor Commented:
Perfect thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now