Control Arrays - Page 2 | ||
Add another staticText control for the second question. Copy and paste responseField and position it as shown below. Notice that its Index is automatically incremented to 1. You now have an array of responseFields with 2 elements. Keep adding questions and responseFields in this way until you have 5 questions and responseFields. | ||
![]() | ||
Now for each responseField we need to set its rightAnswer property. Click on a responseField to select it. In the properties field scroll down to the Behavior section and enter the correct answer as the rightAnswer property as shown below. Do this for all 5 responseFields. | ||
![]() | ||
Step 3- Scoring the Quiz | ||
Now it is time to add a means of scoring to the quiz. Part of the scoring system has already been added. It is the code we put into the TextChange event of our custom contol "answerField". | ||
![]() | ||
As the user types an answer this code checks to see if what the user has typed matches its rightAnswer property. If it matches then the code sets the responseField's "result" property to true. If it doesn't match the "result" property is set to false. | ||
Add a button as shown below to the bottom of Window1. | ||
![]() | ||
In the Action event of the Check Answer pushbutton put the following code. This code checks each responseField's "result" property. If this property is true 1 is added to the 'score". If "result" is false nothing is added to "score". Finally, the score is displayed using a msgBox. | ||
![]() | ||