Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-26-2023, 08:22 AM
Logit Logit is offline Macro Not Tracking Total Score Correctly Windows 10 Macro Not Tracking Total Score Correctly Office 2007
Expert
Macro Not Tracking Total Score Correctly
 
Join Date: Jan 2017
Posts: 591
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default Macro Not Tracking Total Score Correctly

I've been working this challenge for a week without success. Time to get outside help.

Macro records one less correct answer than actually exists. So ... if there are ten correct answers the macro records NINE ... then takes the remainder ( ONE ) and applies it to the next user. If you run the program, selecting all of the correct answers, then look at the RECORD sheet you'll see the NINE and the ONE in Column C.

Your assistance is appreciated. I am open to having the code changed in any manner that will result in a correct result.

Thank you.

Code:
Option Explicit

Private btnClicked As String 'A, B, C, D
Private questionNo As Integer
Private question As String, code As String
Private choiceA, choiceB, choiceC, choiceD As String
Private answer As String

 

Private Sub cmdA_Click()
cmdA.BackColor = &HFF00&
cmdB.BackColor = &HC0FFFF
cmdC.BackColor = &HC0FFFF
cmdD.BackColor = &HC0FFFF
btnClicked = "Answer: A"""
End Sub

Private Sub cmdB_Click()
cmdA.BackColor = &HC0FFFF
cmdB.BackColor = &HFF00&
cmdC.BackColor = &HC0FFFF
cmdD.BackColor = &HC0FFFF
btnClicked = "Answer: B"""
End Sub

Private Sub cmdC_Click()
cmdA.BackColor = &HC0FFFF
cmdB.BackColor = &HC0FFFF
cmdC.BackColor = &HFF00&
cmdD.BackColor = &HC0FFFF
btnClicked = "Answer: C"""
End Sub

Private Sub cmdD_Click()
cmdA.BackColor = &HC0FFFF
cmdB.BackColor = &HC0FFFF
cmdC.BackColor = &HC0FFFF
cmdD.BackColor = &HFF00&
btnClicked = "Answer: D"""
End Sub

Sub resetButton()
cmdA.BackColor = &HC0FFFF
cmdB.BackColor = &HC0FFFF
cmdC.BackColor = &HC0FFFF
cmdD.BackColor = &HC0FFFF
End Sub

 

Private Sub cmdSubmit_Click()
'Check if user click an option
If cmdA.BackColor = &HFF00& Or cmdB.BackColor = &HFF00& Or _
cmdC.BackColor = &HFF00& Or cmdD.BackColor = &HFF00& Then

'Move to the next question
questionNo = questionNo + 1
Label1.Caption = "Question " & questionNo & " of 10"



If cmdSubmit.Caption = "Submit" Then
Call get_quiz
Dim lRow As Integer
lRow = rSH.Range("A" & Rows.Count).End(xlUp).Row + 1
rSH.Range("C" & lRow).Value = rSH.Range("C" & lRow).Value + 1
'rSH.Range("Y1").Value = frm_score.lblScore
txtSampleCode.Text = rSH.Range("C" & lRow).Value
ElseIf cmdSubmit.Caption = "End Exam" Then

'Save the quiz result to record sheet
lRow = rSH.Range("A" & Rows.Count).End(xlUp).Row + 1
rSH.Range("A" & lRow).Value = username
rSH.Range("B" & lRow).Value = Now


frm_score.lblName = username
frm_score.lblScore = rSH.Range("C" & lRow).Value + 1
frm_score.Show
Unload Me
End If

Else
MsgBox "Please select an answer.", vbExclamation, mTitle
End If
End Sub

Private Sub UserForm_Initialize()
questionNo = 1
Call init_SH
Call get_quiz
End Sub

Sub get_quiz()
Call resetButton
Dim lRow As Integer
lRow = questionNo + 1

question = qSH.Range("A" & lRow).Value

choiceA = qSH.Range("B" & lRow).Value
choiceB = qSH.Range("C" & lRow).Value
choiceC = qSH.Range("D" & lRow).Value
choiceD = qSH.Range("E" & lRow).Value
answer = qSH.Range("F" & lRow).Value

txtQuestion.Value = question
cmdA.Caption = choiceA
cmdB.Caption = choiceB
cmdC.Caption = choiceC
cmdD.Caption = choiceD

If qSH.Range("A" & lRow).Value = "" Then
'Last question
'cmdSubmit.Caption = "End Exam"
Unload Me
'Save the quiz result to record sheet
lRow = rSH.Range("A" & Rows.Count).End(xlUp).Row + 1
rSH.Range("A" & lRow).Value = username
rSH.Range("B" & lRow).Value = Now


frm_score.lblName = username
frm_score.lblScore = rSH.Range("C" & lRow).Value
frm_score.Show
Unload Me

End If
End Sub

Attached Files
File Type: xlsm Quiz Example.xlsm (42.3 KB, 5 views)
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Total float not calculating correctly praneetbvb Project 0 04-30-2020 10:17 AM
Macro Not Tracking Total Score Correctly Need to tally check boxes (labeled 1-5) on performance review to get total score based on box value. Learners Permit Word 2 07-16-2018 07:56 PM
Macro Not Tracking Total Score Correctly Macro functioning correctly H28Sailor Excel Programming 2 12-11-2016 03:18 PM
Ad a quiz with different scores for each question and with final score at the end Amadeus PowerPoint 0 09-16-2014 04:24 AM
How to invoke the macro correctly in the workflow smndnm Word VBA 6 07-08-2014 03:13 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:31 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft