PDA

View Full Version : Controlling a text box with VBA



Haitoen
10-17-2009, 12:38 AM
Is it possible to make a text box trigger an action as soon as the correct (pre-determined text) is entered into the text box during a slideshow?

Here's what I want to achieve:
I want to control the TEXTBOX in PPT using VBA, but I do not know how to write the code.

Step 1: Students see a picture with a text box below it.

Step 2: they type the word into the text box.

Step 3: if the word is correct, the a correct P shows and a sound effect ‘bing’ show the student that they typed the word correctly.

Alternative: Have a submit button under the text box, and the student can click on the submit button to see if the answer is correct or not.



This would be great for students' spelling practice.

Any help would be most appreciated, as I am a pre-beginner when it comes to VBA.

Thanks a lot

John Wilson
10-17-2009, 01:20 AM
Insert a control textbox (I'm assuming you know how to do this)
Right Click > View Code

The default code is:
Private Sub TextBox1_Change()

End Sub

This is the code you need as the change event here checks the code every time the text in the box changes!

Between these two lines of code insert code so that in now looks like this :

Private Sub TextBox1_Change()
If TextBox1.Text = "Whatever" Then
'do this
End If
End Sub

The do this part will depend on exactly what you need but the simplest would be a goto slide that has the "well done" and sound.

Private Sub TextBox1_Change()
If TextBox1.Text = "Whatever" Then
SlideShowWindows(1).View.GotoSlide (xx)
End If
End Sub

Haitoen
10-17-2009, 02:50 AM
Insert a control textbox (I'm assuming you know how to do this)
Right Click > View Code

The default code is:
Private Sub TextBox1_Change()

End Sub

This is the code you need as the change event here checks the code every time the text in the box changes!

Between these two lines of code insert code so that in now looks like this :

Private Sub TextBox1_Change()
If TextBox1.Text = "Whatever" Then
'do this
End If
End Sub

The do this part will depend on exactly what you need but the simplest would be a goto slide that has the "well done" and sound.

Private Sub TextBox1_Change()
If TextBox1.Text = "Whatever" Then
SlideShowWindows(1).View.GotoSlide (xx)
End If
End Sub
Hello John

Thank you so much for this. I really appreciate you taking the time to put it down for me.

If I could, I would like to ask you for a little more help in this regard. In your advice you said "do this" would be easiest to go to a slide that says well done. However, I would like them to remain on the same page to spell three such words and continue with other activities.

Is there a way that the "do this" could trigger a little picture of a tick, and a sound effect? If so how should I word the "do this" if the picture was call CORRECT and the sound file called GREAT?

Sorry for the trouble, but I have been trying to solve this for months now with no luck.

Yours gratefully,
Haitoen

P.S. If it would help I can send you a picture of what I am trying to do.

Haitoen
10-17-2009, 09:15 AM
Hello John

I have just learned that the VB textbox in PPT cannot be viewed in PPT viewer. In other words, this type of spelling practice activity is impossible to achieve. Could you please confirm this?

Thanks
Haitoen

John Wilson
10-18-2009, 03:16 AM
If they are using the viewer yes, there is no vba or activx support