Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performing calculations with random numbers

I am trying to make a maths practice powerpoint where students are presented with random addition problems using numbers 1 – 20. I have been working through tutorials by David Marcovtiz (and others) and was using his code as a starting point. As my audience is young students, I would like the maths problems to not be in a message box but in something like text boxes or shapes that I can customise and make large and visually appealing for young students.

So, what I'm wanting to do... In a powerpoint show

  1. Student can click a ‘get started’ button that takes them to next slide
  2. Next slide automatically generates 2 random numbers that student must add together.
  3. Student enters the answer
  4. If answer is correct – I would like something to signify the answer was correct but not something they have to click on to close. Ideally, a little star flashes in the corner then disappears
  5. If the answer is incorrect, a message or picture flashes then disappears.

  6. A new addition problem is automatically/randomly generated I would like to set the number of addition problems to e.g. 20, then have the slide move to a scoring slide that shows their score in pictures e.g. a star for every correct answer.

Update: Using Activex text Boxes:

I have had success with activex text boxes in being able to randomly show two numbers and have them multiply and show the answer in a third activex text box, which I hid off the slide. I used a fourth as an input box for students to type in their answer. If this is the same as the answer in the third box, I can show a star and clear the boxes then move to the next slide. If it's not the same, I can go show another picture then move to the next slide. (I originally wanted the slide to update and use one slide to ask 20 questions but was finding this difficult.)

At present, this requires clicking three command buttons.

What I have managed so far (I know it will seem quite sad to you and possibly unstable, but a major achievement for me and the 'bits' are working) I can manage it for multiplication but when I + the values e.g. 9 + 3, I get 93

Private Sub CommandButton1_Click()
    TextBox1.Value = Int(10 * Rnd)
    TextBox2.Value = Int(10 * Rnd)
    TextBox3.Value = TextBox1.Value * TextBox2.Value
End Sub

Private Sub CommandButton2_Click()
    If TextBox4.Value = TextBox3.Value Then
        ActivePresentation.Slides("problem").Shapes("badge5").Visible = True
        ActivePresentation.Slides("score").Shapes("badge5").Visible = True
    Else 
        ActivePresentation.Slides("problem" _).Shapes("incorrect").Visible = True

        TextBox1.Value = ""
        TextBox2.Value = ""
        TextBox3.Value = ""
        TextBox4.Value = ""
    End If
End Sub

Private Sub CommandButton3_Click()
    SlideShowWindows(1).View.Next
End Sub

What I need

I would like the random numbers in command button 1 to activate automatically.

I would like to combine command button 2 and 3 and include a wait time after the star or incorrect shapes appear before moving to the next slide but the code I have found applies the wait time to the whole sequence as I'm not sure how to include it.

Private Sub Time_Click()
    iTime = 2#
    Start = Timer

    While Timer < Start + iTime
    Wend

    With SlideShowWindows(1).View.Next
    End With  
End Sub

Using Shapes: I would prefer to work with ordinary text boxes or shapes but... I have managed to produce random numbers in shapes but haven't been able to multiply them and have students type into an activex text box that determines whether it is correct or incorrect yet. I think the problem is in trying to use both shapes and an activex textbox.

I would like to use shapes because I would like to create master slide layouts that can be selected using the following code - though this isn't a deal breaker.

Sub background()
    ActivePresentation.Slides.Range(Array(2, 3, 4, 5)).CustomLayout_ 
    = ActivePresentation.Designs(1).SlideMaster.CustomLayouts(6)
End Sub

I feel this is something that other educators could use and am happy to post my finished show if someone is willing and able to assist with the coding. I really appreciate the tolerance and patience of contributors shown to people like myself who have jumped in head first, excited and giving it a go but struggling.

like image 766
Nicpr Avatar asked Mar 19 '16 00:03

Nicpr


1 Answers

So, to break down the pieces you requested in the "What I Need" section, I will split my answer into two sections:

"I would like the random numbers in command button 1 to activate automatically."

I assume what you mean by "automatically" is that you would like the "next" slide to automatically be populated with values after the user answers the question on the previous slide. To accomplish this functionality, I would call the method that the CommandButton1 currently calls after all the logic in the CommandButton2 has been run.

"I would like to combine command button 2 and 3 and include a wait time after the star or incorrect shapes appear before moving to the next slide..."

I would simply combine the code of the two functions with a wait function in between the two bits of code. I'm not sure where you found the code you posted for the "Timer_Click" function, I don't think that would work as currently posted. I would typically use the method of "wait" mentioned in this answer.

The result, after changing the code for the two new requirements would be something like this:

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Sub CommandButton2_Click()
    'Command Button 2(code)
    If TextBox4.value = TextBox3.value Then
        ActivePresentation.slides("problem").Shapes("badge5").visible = True
        ActivePresentation.slides("score").Shapes("badge5").visible = True
    Else
        ActivePresentation.slides("problem").Shapes("incorrect").visible = True

        TextBox1.value = ""
        TextBox2.value = ""
        TextBox3.value = ""
        TextBox4.value = ""
    End If

    'Wait code here(1000ms)
    Sleep 1000

    'Command Button 3(code)
    SlideShowWindows(1).View.Next

    'Call the command for CommandButton1, 
    'this will "automatically" populate the slide with new values
    CommandButton1_Click
End Sub
like image 175
David Rogers Avatar answered Oct 25 '22 04:10

David Rogers