Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
dears,

please assist me in VB.net as from newbie

im trying to make easy MCQ (employees and departments). i have 3 problems :

(before you start reading my issues , please copy and paste all my codes in new form of visual basic and add 4 radio buttons , 1 label and 2 buttons, so the questions will be easily understanding points)

1- i want to randomize the questions - (not the answers)-: always my questions are in the same sequence. for example : question #1 is "rich" , Q2# "Tal" , Q3#"sau".
what i want is to randomize them some times "sau" become Q#1 and so on...

2- if the person answered the right question i dont want to see the question again in the list (unless the person load the form again). for example: "rich" is IT department, if the person choose IT then the quiz continue with the rest of questions " Tal","sau" without the question been answered correctly "rich"

3-i want to move on to the next question directly: in my example: if i choose radio button 1 or 2 or 3 or 4 then i have to click on button 1 to move to the next question.
what i want is to skip the button 1( i want to remove it) and just have the quiz with starting button and 1 label and 4 radio buttons.

for database file:
i dont know how to connect it to data base although i have data base file already from 6 columns. after i load the data base file into the visual basic im not sure how to mingle it with the codes.
therefore please assist me with the normal codes without the database.

thank you very much

What I have tried:

Public Class Form1



Private Structure questionsNanswers
Public Q As String
Public a As String
Public QT As Integer
Public QC As Integer
End Structure

Private wstart As Integer


Private adad As Integer = 10
Private QA(15) As questionsNanswers


Private word(999) As String
Private names(999) As String

Private aray(999) As Integer


Private Sub RandomizeArray(a As Integer, ByRef array() As Integer)

Dim i As Integer
Dim j As Integer
Dim tmp As Integer

Randomize()
For i = 0 To a - 1
j = Int((6 - i + 1) * Rnd() + i)

tmp = array(i)
array(i) = array(j)
array(j) = tmp

Next

End Sub

Private Sub randomize()
Dim r As New Random



End Sub

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
' next

CheckEntry()

wstart = wstart + 1
If wstart >= adad Then
wstart = 0
End If


WriteText()
randomize()

End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
' previous

CheckEntry()

wstart = wstart - 1
If wstart < 0 Then
wstart = adad - 1
End If

WriteText()
End Sub

Private Sub CheckEntry()

RadioButton1.Visible = True
RadioButton2.Visible = True
RadioButton3.Visible = True
RadioButton4.Visible = True

RadioButton1.ForeColor = Color.Black
RadioButton2.ForeColor = Color.Black
RadioButton3.ForeColor = Color.Black
RadioButton4.ForeColor = Color.Black

RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False

End Sub


Private Sub WriteText()

Dim out As Boolean = False

For kk = 0 To 6
aray(kk) = kk
Next
RandomizeArray(7, aray)


Do Until out
For j = 0 To 3
If out = False Then
If aray(j) = QA(wstart).QT Then
out = True
Exit Do
End If
End If
Next

For kkk = 0 To 6
aray(kkk) = kkk
Next
RandomizeArray(7, aray)
Loop

RadioButton1.Text = word(aray(0))
RadioButton2.Text = word(aray(1))
RadioButton3.Text = word(aray(2))
RadioButton4.Text = word(aray(3))





Label1.Text = QA(wstart).Q





' ==============================
' Dim go As Boolean = False
'If go Then
'Dim msg As String
'For ll = 0 To 6
'msg = msg + CStr(aray(ll)) + "|"
'Next

'MsgBox(msg)
'End If

End Sub



Public Sub New()

' This call is required by the designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.
'a
word(0) = "TA"
word(1) = "GR"
word(2) = "HR"
word(3) = "FIN"
word(4) = "commercial"
word(5) = "Proc"
word(6) = "IT"

names(0) = "rich"
names(1) = "Tal"
names(2) = "sau"
names(3) = "pat"
names(4) = "del"



'q and wstart means between ( )
QA(0).Q = names(0)
QA(0).a = word(6)
QA(0).QT = 6
QA(0).QC = -1

QA(1).Q = names(1)
QA(1).a = word(1)
QA(1).QT = 1
QA(1).QC = -1

QA(2).Q = names(2)
QA(2).a = word(2)
QA(2).QT = 2
QA(2).QC = -1

QA(3).Q = names(3)
QA(3).a = word(3)
QA(3).QT = 3
QA(3).QC = -1

QA(4).Q = names(4)
QA(4).a = word(5)
QA(4).QT = 5
QA(4).QC = -1




WriteText()

End Sub

Private Sub RadioButton1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton1.CheckedChanged


If RadioButton1.Checked Then
If StrComp(QA(wstart).a, RadioButton1.Text) = 0 Then
RadioButton1.ForeColor = Color.Red
RadioButton2.Visible = False
RadioButton3.Visible = False
RadioButton4.Visible = False
End If
End If


' If RadioButton1.ForeColor = Color.Red Then
' End If
' If wstart >= adad Then
'wstart = 0

' End If
'wstart = wstart + 1
' If wstart >= adad Then
'wstart = 0
' End If
End Sub

Private Sub RadioButton2_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked Then
If StrComp(QA(wstart).a, RadioButton2.Text) = 0 Then
RadioButton2.ForeColor = Color.Red
RadioButton1.Visible = False
RadioButton3.Visible = False
RadioButton4.Visible = False
End If
End If
End Sub

Private Sub RadioButton3_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton3.CheckedChanged
If RadioButton3.Checked Then
If StrComp(QA(wstart).a, RadioButton3.Text) = 0 Then
RadioButton3.ForeColor = Color.Red
RadioButton1.Visible = False
RadioButton2.Visible = False
RadioButton4.Visible = False
End If
End If
End Sub

Private Sub RadioButton4_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton4.CheckedChanged
If RadioButton4.Checked Then
If StrComp(QA(wstart).a, RadioButton4.Text) = 0 Then
RadioButton4.ForeColor = Color.Red
RadioButton1.Visible = False
RadioButton2.Visible = False
RadioButton3.Visible = False
End If
End If

End Sub

Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click



End Sub

Private Sub RadioButton1_Click(sender As Object, e As EventArgs) Handles RadioButton1.Click


End Sub

Private Sub RadioButton1_MouseClick(sender As Object, e As MouseEventArgs) Handles RadioButton1.MouseClick


' If RadioButton1.Checked Then
'If StrComp(QA(wstart).a, RadioButton1.Text) = 0 Then



'RadioButton1.ForeColor = Color.Red
'RadioButton2.Visible = False
'RadioButton3.Visible = False
'RadioButton4.Visible = False
'End If

' End If
' moveto()

End Sub
Private Sub moveto()

wstart = wstart + 1
If wstart >= adad Then
wstart = 0
End If

'random()
WriteText()


' If RadioButton1.ForeColor = Color.Red Then MessageBox.Show("correct") Else MessageBox.Show("false")
' If RadioButton2.ForeColor = Color.Red Then Label1.Text = QA(wstart).Q
' If RadioButton3.ForeColor = Color.Red Then Label1.Text = QA(wstart).Q
' If RadioButton3.ForeColor = Color.Red Then Label1.Text = QA(wstart).Q


End Sub

End Class
Posted
Updated 19-May-18 1:17am
Comments
Richard MacCutchan 19-May-18 5:54am    
Please do not dump a load of unformatted code and tell people to debug it for you. Explain exactly what the problem is and show only the relevant code, within <pre> tags, so it is readable.
Member 13834531 19-May-18 6:10am    
ok i appolgise... perhaps here is my issue how to randomize it: Label1.Text = QA(wstart).Q
Richard MacCutchan 19-May-18 6:38am    
Create a collection (List<t>) and use random values to select an item.
Member 13834531 19-May-18 6:56am    
can you please if you dont mind explain it in the codes? i really didnt get quite well.
Richard MacCutchan 19-May-18 6:59am    
See List(T) Class (System.Collections.Generic)[^] and Random Class (System)[^]. You will learn so much more by trying it yourself.

1 solution

VB
Sub Main()
    Dim questions As New List(Of KeyValuePair(Of String, String))
    questions.Add(New KeyValuePair(Of String, String)("What is the capital of England?", "London"))
    questions.Add(New KeyValuePair(Of String, String)("What is the capital of France?", "Paris"))
    questions.Add(New KeyValuePair(Of String, String)("What is the capital of Germany?", "Berlin"))

    Dim qNumber As New Random()
    For i As Integer = 0 To 5

        Dim qi As Integer = qNumber.Next() Mod questions.Count
        Dim qa As KeyValuePair(Of String, String) = questions.ElementAt(qi)
        Console.WriteLine(qa.Key)
        Console.WriteLine(qa.Value)
    Next
    Console.ReadLine()

End Sub


Updated for VB.NET
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900