Import Questions & Answers of a Microsoft PowerPoint Multiple-Choice Quiz...Read More
How to create FILL IN THE BLANKS in PowerPoint Game Tutorial
This fill in the blanks quiz game PowerPoint module allows the student to type the answer in an ActiveX Element TextBox.
We then cross-check the answer with the correct answer which is stored within a shape placed outside the slide via an If-Then-Else Conditional Statement.
It allows the teachers to quickly modify the template and edit the correct answer without having to change any VBA Macro Codes.
This amazing customisable Microsoft PowerPoint Fill in the Blanks Template can be
repurposed as an interactive educational tool using Visual Basic Applications in PowerPoint.
Sub Initialise() For i = 2 To 6 'change the numbers accordingly' ActivePresentation.Slides(i).Shapes("AA").OLEFormat.Object.Value = "" Next i ActivePresentation.SlideShowWindow.View.Next End Sub
Sub CheckAnswer() Dim CS As Slide Set CS = ActivePresentation.SlideShowWindow.View.Slide 'represents the current slide presented, not the slide number' If UCase(CS.Shapes("AA").OLEFormat.Object.Value) = UCase(CS.Shapes("CA").TextFrame.TextRange) Then MsgBox "Correct Answer" ActivePresentation.SlideShowWindow.View.Next Else MsgBox "Wrong Answer. Try Again!" End If End Sub
ActiveX Element - TextBox in PowerPoint
This is a very versatile tool for teachers and educators if you want to collect input data from your students.
By using the TextBox1.Value function, we can read the input data which your student has typed.
Then, we use an If-Then-Else condition statement to crosscheck the Input Answer with the Correct Answer.
Why do we use Ucase in VBA?
“Answer” is not the same as “answer” or “ANSWER” or “AnSwer”
All the above are not equal and are considered to be different strings in Visual Basic Applications. Thus, if the correct answer was in lowercase and the student inputs the correct answer but in uppercase, the code would understand that the answer is incorrect.
Thus, to fix this issue, we convert all the characters of the correct answer and the input answer into uppercase and then ask the macro to check whether the answer is correct or wrong.
One Code for Hundred Slides
This is what makes my tutorial and code stand out from the rest of the modules. Conventionally, we would not use a shape to store data but it is extremely convenient and feasible.
Instead of storing the data inside a shape which is placed outside the slide, programmers would use an Array to store all the answers but that would not be the best course of action in terms of ease for customisability.
ADDING SCORING SYSTEM
We successfully created a fill in the blanks game in powerpoint where a student can type their input answer in the slideshow itself.
Now it is time to make a result slide for this module which will show the number of correct answers, wrong answers and also the number of questions which were not attempted due to the time limit.
You can add a time limit for each question in the next module.
We can easily embed a scoring system in powerpoint games using labels which increase if the question is answered correct. However in this module, we have an option of attempting the wrong answer multiple times until the student answers that correctly. However, we should only count the first attempt. Thus, we use a Boolean (data class with values True or False) which will allow us to know if the question is attempted or not.
Dim QuestionAttempted As Boolean
'this part of the code is just for your understanding' '1. Question is not attempted' QuestionAttempted = False '2. Question is attempted' QuestionAttempted = True
The above Boolean allows us to record whether the question was attempted or not. We need to declare that in the beginning of the module since we will be using that variable inside multiple sub-routines.
Copy the full code by downloading this .pptm module template file for free!
Sub Initialise() QuestionAttempted = False SlideLayout31.CA.Caption = 0 SlideLayout31.WA.Caption = 0 For i = 2 To 6 ActivePresentation.Slides(i).Shapes("AA").OLEFormat.Object.Value = "" Next i ActivePresentation.SlideShowWindow.View.Next End Sub
Sub CheckAnswer() Dim CS As Slide Set CS = ActivePresentation.SlideShowWindow.View.Slide 'To find whether AA = CA' If UCase(CS.Shapes("AA").OLEFormat.Object.Value) = UCase(CS.Shapes("CA").TextFrame.TextRange) Then MsgBox "Correct Answer" If QuestionAttempted = False Then SlideLayout31.CA.Caption = (SlideLayout31.CA.Caption) + 1 End If ActivePresentation.SlideShowWindow.View.GotoSlide (CurrentSlideNo + 1) QuestionAttempted = False CalculateUnattemptedAnswer Else MsgBox "Wrong Answer. Try Again!" If QuestionAttempted = False Then SlideLayout31.WA.Caption = (SlideLayout31.WA.Caption) + 1 End If QuestionAttempted = True CalculateUnattemptedAnswer End If End Sub
ActiveX Element - Label in PowerPoint
We can insert Labels in a Slide-Master and increase the number withing the label to keep count of the number of questions answered current and the number answered incorrectly.
The code is exactly the same as our counter or scoreboard module in which we increased the Label’s Caption by +1.
Thus, we just use the Caption property of the Label and show the results in the last slide of our Presentation.
Recording only the first attempt in Counter
As explained earlier, only the first attempted answer in the fill in the blanks question was counted with the “QuestionAttempted” Boolean.
This technique can be incorporated in various other modules to calculate only the first attempt of the user.
We just need to change the value of the Boolean and with If-Then Conditional statements, we can modify the existing macro codes and make provisions as per our requirements.
ADDING TIME LIMIT PER SLIDE
How to add a 10 seconds time limit for every question slide?
We can easily do this in just two steps. Select your question slides and then go to the Transitions Tab and select “Advance Slide”. Here you can input the value in seconds. You can customise the time limit as per your needs.
To show the passage of time, we can insert a rectangle at the top and insert an exit wipe animation whose duration will also be for 10 seconds.
We have to make appropriate changes in our VBA Macro codes too. We now have another category to insert in the last result slide – Number of Unattempted Answers. We can make its provision by making another Label and using the following subroutine to calculate that:
Sub CalculateUnattemptedAnswer() SlideLayout31.UA.Caption = (5) - (SlideLayout31.CA.Caption) - (SlideLayout31.WA.Caption) End Sub
Overall time limit in powerpoint game
Currently, I haven’t made a module which has a single time limit for the entire powerpoint game. The main reason being its lack of customisability while showing the progress of time throughout multiple slide. We can definitely embed a video counter but those counters get paused when a message box pops up.
However, if you are not using any message boxes, feel free to use this code:
Dim WAIT As Double WAIT = Timer While Timer < WAIT + 15 DoEvents 'do nothing' Wend
Time-limit via Transititions Tab in powerpoint
There is an inbuilt option to advance to the next slide in slide-show mode using a feature present in the transitions tab!
Just check mark ‘Advance Slide’ and mention the required seconds and viola! your powerpoint game has an amazing time limit now!
HOW TO ADD MULTIPLE FILL IN THE BLANKS
Add multiple ActiveX TextBoxes to our PowerPoint Slide thus, having multiple blanks in our Fill in the Blanks Game in PowerPoint. This seems simple enough, we now just have to cross check each and every attempted answer with the correct answer shape which is placed outside the slide.
Rename “AA” as “AA1” via selection pane and do the same with CA, i.e “CA” becomes “CA1”. Now, we just have to duplicate our code which will equate both the values one-by-one.
Instead of duplicating the code, we can use a For Loop which will generate number from 1 To 4 in this case. So, AA1 = CA1 to AA4 = CA4 is checked.
Also, changing the shape name from “CA” to “CA1” in multiple slides can be very tedious. Thus, we can use a simple VBA Macro Code in Microsoft PowerPoint which will allow us to rename the Shape’s name:
For i = 3 To 6 ActivePresentation.Slides(i).Shapes("AA").OLEFormat.Object.Name = "AA1" ActivePresentation.Slides(i).Shapes("CA").Name = "CA1" Next i
Cross checking AA with CA multiple times using For Loop in PPT VBA
During our loop, we increase the value of the “CorrectBlanks” integer by +1 every time “AA” & i is equal To “CA” & i.
We also set the value of NoOfBlanks to be equal to i.
Thus, the above integer keeps getting updated until an error pops up saying that the Shape “AA” & i doesn’t exist.
At the point of time, we go to CheckIfAllCorrect: in our VBA Macro and then add an If-Condition.
If the number of blanks is equal to the number of CorrectBlanks, we can successfully move on to the next question.
And once that happens, we can reset the value of CorrectBlanks to 0.
Sub Initialise() For i = 2 To 7 For a = 1 To 20 'maximum number of blanks On Error Resume Next ActivePresentation.Slides(i).Shapes("AA" & a).OLEFormat.Object.Value = "" Next a Next i ActivePresentation.SlideShowWindow.View.Next End Sub
Sub CheckAnswer() Dim CS As Slide "CS Stands for Current Slide" Set CS = ActivePresentation.SlideShowWindow.View.Slide CorrectBlanks = 0 For i = 1 To 10 On Error GoTo CheckIfAllCorrect If UCase(CS.Shapes("AA" & i).OLEFormat.Object.Value) = UCase(CS.Shapes("CA" & i).TextFrame.TextRange) Then MsgBox "Correct Answer", vbInformation, "Answer " & i CorrectBlanks = CorrectBlanks + 1 Else MsgBox "Wrong Answer. Try Again!", vbCritical, "Answer " & i End If NoOfBlanks = i Next i CheckIfAllCorrect: If CorrectBlanks = NoOfBlanks Then ActivePresentation.SlideShowWindow.View.Next End If End Sub