Good evening mga sir, hingi lng po sana ako ng tulong sa capstone project ko. Ang system ko po ay Computer-based Entrance Exam, bale nagge-generate na po sya ng questions in random order pro sa exam form ko po isang question lang yong naka display. Ang recommendation po ng Dean ko mas mabuti daw kung five questions yong mag display instead of one but still in a random order pra daw po ma-avoid ang pag click ng next button.
Ito po yong screenshot ng exam form:
View attachment 229233
At ito po yong code:
*connection
Imports MySql.Data.MySqlClient
Public Class frmEnglish
Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=dbentex;User ID=root;Password=;")
Dim con1 As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=dbentex;User ID=root;Password=;")
Dim Query As String
Dim Query1 As String
Dim reader As MySqlDataReader
Dim cmd As MySqlCommand = New MySqlCommand(query, con)
Dim da2 As New MySqlDataAdapter
Dim cache As Object
Dim da As New MySqlDataAdapter
Dim temp As String
Dim MyIndex As Integer = 0
Dim qnum As Integer, correct As Integer, wrong As Integer, ave As Double
*random order
Private Sub Random(ByVal unit As Integer)
Dim list As New ArrayList
For i As Integer = 3 To 5
list.Add(i)
Next i
Dim rnd As New Random
Dim ind, j As Integer
Dim Reader As Object
j = 0
If unit < dgvquestions.RowCount Then
While list.Count > 0
ind = rnd.Next(0, list.Count)
Reader = list(ind)
list.RemoveAt(ind)
If j = 0 Then
rb1.Text = dgvquestions.Item(Convert.ToInt32(Reader.ToString()), unit).Value.ToString
ElseIf j = 1 Then
rb2.Text = dgvquestions.Item(Convert.ToInt32(Reader.ToString()), unit).Value.ToString
ElseIf j = 2 Then
rb3.Text = dgvquestions.Item(Convert.ToInt32(Reader.ToString()), unit).Value.ToString
ElseIf j = 3 Then
rb4.Text = dgvquestions.Item(Convert.ToInt32(Reader.ToString()), unit).Value.ToString
End If
j = j + 1
'MsgBox(Reader.ToString())
End While
End If
End Sub
*display question
Public Sub qdisplay()
con.Close()
con.Open()
cmd = New MySqlCommand("SELECT * from tblquestions where subject_c LIKE '" & lblSub_c.Text & "' AND glevel LIKE '" & lblGL.Text & "' ORDER by RAND()", con)
Reader = cmd.ExecuteReader
While Reader.read
dgvquestions.Rows.Add(New String() {reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5), reader.GetValue(6), reader.GetValue(7), reader.GetValue(8)})
End While
con.Close()
End Sub
*display textbox
Private Sub DisplayTextbox()
Try
con.Close()
con.Open()
cmd = New MySqlCommand("SELECT * FROM tblquestions where question_c like '" & dgvquestions.CurrentCell.Value & "'", con)
reader = cmd.ExecuteReader
While reader.Read
txtqid.Text = reader.GetValue(0)
txtqname.Text = reader.GetValue(1)
rb1.Text = reader.GetValue(4)
rb2.Text = reader.GetValue(5)
rb3.Text = reader.GetValue(6)
rb4.Text = reader.GetValue(7)
txtkey.Text = reader.GetValue(8)
End While
con.Close()
Catch ex As Exception
MsgBox("There are no available questions", MsgBoxStyle.Critical)
Me.Close()
End Try
End Sub
*Next button
Private Sub btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnext.Click
If dgvquestions.RowCount > 0 Then
Dim MyIndex As Integer = 0
If dgvquestions.CurrentRow.Index < dgvquestions.RowCount Then
MyIndex = dgvquestions.CurrentRow.Index + 1
End If
dgvquestions.ClearSelection()
'score
If rb1.Checked = True And rb1.Text = txtkey.Text Then
correct = correct + 1
lblcorrect.Text = correct
ElseIf rb2.Checked = True And rb2.Text = txtkey.Text Then
correct = correct + 1
lblcorrect.Text = correct
ElseIf rb3.Checked = True And rb3.Text = txtkey.Text Then
correct = correct + 1
lblcorrect.Text = correct
ElseIf rb4.Checked = True And rb4.Text = txtkey.Text Then
correct = correct + 1
lblcorrect.Text = correct
Else
wrong = wrong + 1
lblwrong.Text = wrong
End If
txtscore.Text = lblcorrect.Text
'end score
'-----------------------------------------------
'question number
qnum = Val(Label4.Text)
If qnum >= Val(lblLimit.Text) Then
' MessageBox.Show("maximum number of questions", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
con.Close()
con.Open()
othercompute()
Query = "INSERT INTO tblscore(score_c,score,overall,percentage,subject_c,ornum)VALUES('"
Query = Query + txtScoreC.Text + "','" + txtscore.Text + "','" + lblLimit.Text + "','" + lblMulti.Text + "','" + lblSub_c.Text + "','" + frmMainStudent.lblOR.Text + "')"
Dim cmd As New MySqlCommand(Query, con)
Dim i As Integer = cmd.ExecuteNonQuery()
con.Close()
MsgBox(frmMainStudent.cmbSubject.Text + " Examination Done", MsgBoxStyle.Information)
MsgBox("Your correct is " + txtscore.Text + " out of " + lblLimit.Text, MsgBoxStyle.Information)
MsgBox("Equivalent to " + lblMulti.Text, MsgBoxStyle.Information)
Me.Close()
'frmStudentExam.Label2.Text = lblcorrect.Text
'ave = (Val(frmStudentExam.Label2.Text) + Val(frmStudentExam.Label3.Text) + Val(frmStudentExam.Label4.Text)) / 3
'frmStudentExam.Label5.Text = ave
'Me.Close()
'Label4.Text = 1
End If
'end of question number
If MyIndex < dgvquestions.RowCount Then
'datathrow()
'Examcount()
dgvquestions.CurrentCell = dgvquestions.Rows(MyIndex).Cells(0)
txtqid.Text = dgvquestions.Item(0, MyIndex).Value.ToString
txtqname.Text = dgvquestions.Item(1, MyIndex).Value.ToString
rb1.Text = dgvquestions.Item(4, MyIndex).Value.ToString
rb2.Text = dgvquestions.Item(5, MyIndex).Value.ToString
rb3.Text = dgvquestions.Item(6, MyIndex).Value.ToString
rb4.Text = dgvquestions.Item(7, MyIndex).Value.ToString
txtkey.Text = dgvquestions.Item(8, MyIndex).Value.ToString
dgvquestions.Rows(MyIndex).Selected = True
' Random(MyIndex)
Else
btnSubmit.Visible = True
' Examcount()
End If
qnum = Val(Label4.Text) + 1
Label4.Text = qnum
If qnum < Val(lblLimit.Text) Then
btnnext.Text = "Next"
Else
btnnext.Text = "Submit"
End If
End If
__________________________
MARAMING SALAMAT PO SA TULONG MGA SIR