Good Evening, A friend, and I are working on a software for EMT/Paramedics can take practice test while at the station. I haven't programmed in over 15 years so I'm kind of out of date. I would like the program to instead of reading a txt file to read a Microsoft access db. Our info for our access is listed below
MS Access DB: ETPro_Database Table: QuestionBank_Table Columns: Question / Image attachment / Correct Answer
As a firefighter with some programming knowledge I'm still learning lol, and eventually I would like to add a student login/pass, second screen to choose which exam to take, and a submit button to calculate total of the exam.
Thank you, and have a good day,
G
Imports System.IO
Partial Public Class Form1
Public Sub New()
InitializeComponent()
End Sub
Private currentQuestion As Integer
Private listOfQuestions As List(Of Question) = New List(Of Question)
Public Class Question
Public Property Question As String
Public Property Choice1 As String
Public Property Choice2 As String
Public Property Choice3 As String
Public Property Choice4 As String
Public Property Answer As String
End Class
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
' open a text file
Using reader = New StreamReader("C:\exam\quiz2.txt")
' read a line
Dim line = reader.ReadLine()
'loop as long as it's not empty
While (Not String.IsNullOrWhiteSpace(line))
' create a question instance and put the data into it
Dim question = New Question
question.Question = line
question.Choice1 = reader.ReadLine()
question.Choice2 = reader.ReadLine()
question.Choice3 = reader.ReadLine()
question.Choice4 = reader.ReadLine()
question.Answer = reader.ReadLine()
' add the question into the list
listOfQuestions.Add(question)
' read next question
line = reader.ReadLine()
End While
End Using
Catch ex As Exception
MsgBox("Error message here")
End Try
' load first question
If listOfQuestions.Count > 0 Then
LoadQuestion(0)
End If
End Sub
Sub LoadQuestion(questionIndex As Integer)
Dim question = listOfQuestions(questionIndex)
currentQuestion = questionIndex
With question
lblQuestion.Text = .Question
radChoice1.Text = .Choice1
radChoice2.Text = .Choice2
radChoice3.Text = .Choice3
radChoice4.Text = .Choice4
End With
End Sub
Private Sub btnPreviousQuestion_Click(sender As System.Object, e As System.EventArgs) Handles btnPreviousQuestion.Click
If (currentQuestion > 0) Then
LoadQuestion(currentQuestion - 1)
End If
End Sub
Private Sub btnNextQuestion_Click(sender As System.Object, e As System.EventArgs) Handles btnNextQuestion.Click
If (currentQuestion < listOfQuestions.Count - 1) Then
LoadQuestion(currentQuestion + 1)
End If
End Sub
End Class```