0

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```
Gerard
  • 9
  • 1
  • 1
    While I appreciate the intent of this project you've not really given us a whole heap to work with. This site is really intended to help with specific issues and does expect that you do some research before asking. There are thousands of walkthoughs avaliable on wotking with Access https://docs.microsoft.com/en-us/visualstudio/data-tools/connect-to-data-in-an-access-database-windows-forms?view=vs-2019. Or maybe rework your question some. Take a look at the site tour which will explain how to ask – Hursey Oct 07 '21 at 01:38
  • I'm going to leave this here, this will set you up to do it correctly: https://stackoverflow.com/q/15148588/495455 – Jeremy Thompson Oct 07 '21 at 01:43
  • I'm sorry maybe I should of asked a different way. I know how to connect to a database however for my Label1 to show the question I don't know how to attach the Question from the db to the Label1 – Gerard Oct 07 '21 at 01:45
  • Move the ListOfQuestions and LoadQuestion() method to the business logic class then bind the labels: https://stackoverflow.com/questions/36664065/binding-a-label-to-a-property and see MSDN: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.bindingsource.list?view=windowsdesktop-5.0 – Jeremy Thompson Oct 07 '21 at 02:18

0 Answers0