I am able to set up a variable for 'level' and want to write some code so that whatever is selected then that table / questions will be selected and displayed to the user.
The way I'm thinking at the moment seems very long winded. I think I'll have to write an IF ELSE statement/case statement for each of the 'navigaterecords' and the sql statment for beginners, intermediate and advanced.
Does anyone know a much 'neater' way? PLEASE remember that I am relatively new to programming. Thanks.
here is the code so far for the quiz form.
Assume there is a variable 'LEVEL' - have not actually done this yet. Where the code refers to 'advanced' is where I have been trying it out to select questions from the advanced table.
Imports System.Data
Imports System.Random
Imports System.Data.OleDb
Public Class lblScore
Dim sql As String
Dim da As OleDb.OleDbDataAdapter
Dim con As New OleDbConnection
Dim dbprovider As String
Dim dbsource As String
Dim inc As Integer
Dim ds As New DataSet
Dim MaxRows As Integer
Dim score As Integer
Dim dtStart As Date
Private Sub navigateRecords()
TextBox1.Text = ds.Tables("Advanced").Rows(inc).Item(0)
TextBox2.Text = ds.Tables("Advanced").Rows(inc).Item(1)
TextBox3.Text = ds.Tables("Advanced").Rows(inc).Item(2)
TextBox4.Text = ds.Tables("Advanced").Rows(inc).Item(3)
TextBox5.Text = ds.Tables("Advanced").Rows(inc).Item(4)
TextBox6.Text = ds.Tables("Advanced").Rows(inc).Item(5)
TextBox7.Text = inc
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
label_1.Text += 1
If label_1.Text = 60 Then
label_1.Text = "00"
Label_2.Text += 1
ElseIf Label_2.Text = 60 Then
Label_2.Text = "0"
Label_3.Text += 1
End If
End Sub
Private Sub BtnNextQ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNextQ.Click
Timer1.Interval = "1000"
If BtnNextQ.Text = "Next Question" Then
Timer1.Enabled = True
End If
BtnNextQ.Visible = False
btnCheck.Visible = True
'navigateRecords()
If inc <> MaxRows - 1 Then
inc = inc + 1
navigateRecords()
Else
MsgBox("No More Rows")
End If
End Sub
Private Sub frmQuiz_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim con As New OleDbConnection
con.ConnectionString = "provider=microsoft.jet.OleDb.4.0;data source=z:/new.mdb;"
con.Open()
sql = "Select * From Advanced order by rnd(QuestionNumber)"
da = New OleDbDataAdapter(sql, con)
da.Fill(ds, "Advanced")
con.Close()
MaxRows = ds.Tables("Advanced").Rows.Count
inc = -1
End Sub
Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
Dim Myanswer As String
txtCorrect.Text = ds.Tables("Advanced").Rows(inc).Item(6)
If RbtnA.Checked = True Then
Myanswer = "A"
' txtMyAnswer.Text = Myanswer
ElseIf RbtnB.Checked = True Then
Myanswer = "B"
' txtMyAnswer.Text = Myanswer
ElseIf RbtnC.Checked = True Then
Myanswer = "C"
' txtMyAnswer.Text = Myanswer
ElseIf RbtnD.Checked = True Then
Myanswer = "D"
' txtMyAnswer.Text = Myanswer
End If
If Myanswer = txtCorrect.Text Then
score = score + 1
lblS.Text = score
MsgBox("Correct Answer")
Else
MsgBox("Incorrect Answer")
End If
If inc <> MaxRows - 1 Then
inc = inc + 1
navigateRecords()
Else
MsgBox("No More Rows")
End If
End Sub
Private Sub BtnNextQ_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnNextQ.VisibleChanged
End Sub
End Class

New Topic/Question
Reply



MultiQuote









|