Quiz Template, for Visual Basic.NET

duyen

New Member
Reaction score
214
This is a console based quiz template, which is rather self explanatory for Microsoft Visual Basic.NET 2008.

Just change what needs to be changed in the config sections.

Copy this code:
Code:
Module Program
    Public numberofquestions As Integer
    Public CorrectMessage As String
    Public WrongMessage As String
    Public AnswersCorrect As Integer
    Public AnswersWrong As Integer
    Public Rating(5) As String
    Public WelcomeMessage As String
    Public quizname As String
    'start of console macros
    Function tm_displayget(ByVal message As String)
        'This function writes a message and returns the response
        Console.WriteLine(message)
        Dim tm_response As String
        tm_response = Console.ReadLine
        Return LCase(tm_response)
    End Function
    Function tm_askquestion(ByVal question As String, ByVal answer As String)
        'This function writes the question, and returns 0 if the person gets the question wrong
        ' or 1 if they get it right.
        Dim tm_temp As String
        tm_temp = tm_displayget(question)
        tm_temp = LCase(tm_temp)
        Dim tm_answer = LCase(answer)
        If tm_temp = answer Then
            Return 1
        Else
            Return 0
        End If
    End Function
    Sub tm_error(ByVal errormsg As String)
        'This will write the errormsg and beep
        Console.WriteLine(errormsg)
        Console.Beep()
    End Sub
    'end of console macros
    Sub Main()
        '=============================
        '=        CONFIGURE          =
        '=============================
        numberofquestions = 5
        '=============================
        '=       END CONFIGURE       =
        '=============================
        Dim q_question(numberofquestions) As String
        Dim q_answer(numberofquestions) As String
        '=============================
        '=        CONFIGURE          =
        '=============================
        q_question(1) = "What's 5+5?"
        q_answer(1) = "10"
        q_question(2) = "What's 8 / 2?"
        q_answer(2) = "4"
        q_question(3) = "What's the third letter of the alphabet?"
        q_answer(3) = "c"
        q_question(4) = "What's 6 times 7?"
        q_answer(4) = "42"
        q_question(5) = "What's 5 times 3?"
        q_answer(5) = "15"
        quizname = "Kindergarten Quiz"
        '=============================
        '=       END CONFIGURE       =
        '=============================
        '=============================
        '=    OPTIONAL CONFIGURE     =
        '=============================
        WrongMessage = "Wrong!"
        CorrectMessage = "Correct!"
        Rating(1) = "Horrible"
        Rating(2) = "Bad"
        Rating(3) = "Average"
        Rating(4) = "Good"
        Rating(5) = "Perfect!"
        WelcomeMessage = "Welcome to the " & quizname & "! This quiz template was brought to you by Anman64."
        '=============================
        '=       END CONFIGURE       =
        '=============================
        Console.WriteLine(WelcomeMessage)
        Dim i As Integer
        'Displays questions
        Do Until i = numberofquestions
            i = i + 1
            Dim s As Integer = tm_askquestion(q_question(i), q_answer(i))
            If s = 0 Then
                Call tm_error(WrongMessage)
                AnswersWrong = AnswersWrong + 1
            Else
                Console.WriteLine(CorrectMessage)
                AnswersCorrect = AnswersCorrect + 1
            End If
        Loop
        'Displays results
        Dim t_integer As Integer = AnswersCorrect * 100 / numberofquestions
        Console.WriteLine("You got " & AnswersCorrect & " answers(s) correct and " & AnswersWrong & " answer(s) wrong.")
        Console.WriteLine("Which totals up to be " & t_integer & "% correct.")
        Dim ti As Integer
        'Determines the rating
        If t_integer < 21 Then
            ti = 1
        ElseIf t_integer < 41 Then
            ti = 2
        ElseIf t_integer < 61 Then
            ti = 3
        ElseIf t_integer < 81 Then
            ti = 4
        ElseIf t_integer = 100 Then
            ti = 5
        Else : ti = 4
        End If

        'restarts or exits
        Console.WriteLine("Your score is " & Rating(ti))
        Console.WriteLine("Type 'exit' to get out or type 'restart' to retake the quiz.")
        If Console.ReadLine = "restart" Then
            Call Main()
        Else
            End
        End If
    End Sub
End Module

Yeah, I'm aware this could be made slightly more configurable with ratings, but oh well.


Oh and if you need to add more questions just do this:
Code:
        q_question(6) = "What's 6 times 5?"
        q_answer(6) = "30"
 

The Helper

Necromancy Power over 9000
Staff member
Reaction score
1,698
Miss the days when people used to share this kind of stuff!
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top