Results 1 to 4 of 4

Thread: Need help with Objective Type questions (Quiz)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Exclamation Need help with Objective Type questions (Quiz)

    Dear Professionals,

    I am a DIYer and I am still learning VBA. Using different function found online, I build a Quiz. It is working but there is one thing I can't figure out. What I need is when a person pick his/her answer, user form must show(highlight in green) him the correct answer, so that a person knows if he/she answered correctly, before clicking next button .
    I attached screenshots of my userform and this is my code:

    Private Sub Button_Click()
    If (Answer1.Value = True) Then
        ans = 1
    ElseIf (Answer2.Value = True) Then
        ans = 2
    ElseIf (Answer3.Value = True) Then
        ans = 3
    ElseIf (Answer4.Value = True) Then
        ans = 4
    End If
    ansacc = CInt(Range("Questions!F" & Counter).Text)
    If (ansacc = ans) Then
        status.Width = status.Width + 1
    
    End If
    
    Answer1.Value = False
    Answer2.Value = False
    Answer3.Value = False
    Answer4.Value = False
    Counter = Counter + 1
    qcounter = qcounter + 1
    If qcounter <= 50 Then
    While (Range("Questions!G" & Counter).Text <> "A")
        Counter = Counter + 1
    Wend
    Question.Caption = Range("Questions!A" & Counter).Text
    Answer1.Caption = Range("Questions!B" & Counter).Text
    Answer2.Caption = Range("Questions!C" & Counter).Text
    Answer3.Caption = Range("Questions!D" & Counter).Text
    Answer4.Caption = Range("Questions!E" & Counter).Text
    End If
    Counterq.Caption = Range("Count!A5").Value
    Range("Count!D1").Value = status.Width
    Button.Enabled = False
    
    If qcounter < 50 Then
    Frame1.Visible = False
    Label2.Visible = False
    correct.Visible = False
    Label3.Visible = False
    rate.Visible = False
    Label4.Visible = False
    EOC.Visible = False
    Label5.Visible = False
    preeoc.Visible = False
    End If
    
    If qcounter = 50 Then
    Frame1.Visible = True
    Label2.Visible = True
    correct.Visible = True
    Label3.Visible = True
    rate.Visible = True
    Label4.Visible = True
    EOC.Visible = True
    Label5.Visible = True
    preeoc.Visible = True
    
    correct.Caption = Range("Count!D1").Value
    rate.Caption = Range("Count!D2").Value
    EOC.Caption = Range("Count!D3").Value
    preeoc.Caption = Range("Count!D4").Value
    Button.Enabled = False
    
    End If
    
    End Sub
    Attached Images Attached Images
    Last edited by Bob Phillips; 06-04-2020 at 01:23 AM. Reason: Added code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •