VBA MsgBox weirdness

D

Dianne Aldridge

I've got some 3rd-grade classes using an interactive PP lesson that
pops up a message box asking for their name; it is displayed on their
score sheet at the end of the lesson. Today, a whimsical student
decided to input "www.simcity.com" when prompted. Now the
"www.simcity.com" will not go away; when another student starts the
lesson and enters his name, "www.simcity.com" is displayed in place of
his name. The PP lesson is stored in a .pps file, so I don't have a
clue why this text is apparently being 'saved' back to the file. Reboot
did not fix.

The only thing that I think of is that by entering "www." that somehow
a link or something was established. But that doesn't make sense, so I
don't know.

Any ideas, oh PP gurus? :)
 
S

Shyam Pillai

Hello Dianne,
Unless there is the relevant code segment to look at it would be difficult
to speculate on the cause of the problem.
 
D

David M. Marcovitz

Dianne,

Shyam is right. We'll need some code. I just tried typing a Web site
address into several of my examples and could not duplicate the behavior
you describe. I used examples that create printable slides and examples
that modify the text on a slide. In every case, the Web site did not turn
into a link automatically and the text was properly replaced by the code
on the next go-round.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 
D

Dianne Aldridge

Shyam,
The relevant section of code is below. It's just a simple InputBox
(oops, I think I originally said MsgBox) that retains the student's
name and has always worked correctly. Very strange. Thanks for taking a
look.


Sub StartLesson()

MakeVisible
HideGoBackButtons

HaveName = False
While Not HaveName
StudentName = InputBox(prompt:="Please type your name in
the space below", Title:="Student Name")
If StudentName = "" Then
HaveName = False
Else
HaveName = True
' MsgBox (StudentName & ", don't forget to look at your
checklist to see where you need to begin studying.")
End If
Wend

ActivePresentation.SlideShowWindow.View.GotoSlide (2)

End Sub
 
D

David M. Marcovitz

Dianne,

I'm fairly sure that this isn't the code segment that is having trouble.
Can you describe in more detail what is happening? For example, where is
the website/name showing up, and where is it staying? Does this happen
when a student clicks on a Start Over button at the end and goes back
through the presentation? Does it happen when the presentation is quit
and started again? Perhaps, you should email the presentation to me, so I
can look at it in more detail.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 
D

Dianne Aldridge

David,
It's just a simple quiz that starts by asking for the student's name
via InputBox. They input the name, click OK, and continue through the
quiz. For this lesson, there is no immediate feedback, so the name is
not used during the quiz. After the last question, a printable score
slide (almost identical to the example in your book) is produced with
their name on the top. The website name was entered by the student in
the InputBox and appeared on the printable score slide; when another
student uses that same PP from the Start button, they enter their name,
but the printable slide still shows the website name.Yes, it still
happens when the PP is restarted - and also when the computer is
rebooted. I'm using this identical PP on 20 other lab computers with no
problem. Only one student entered a web address for his name!

I would love to email you the PP, but the file is 8 MG and I'm using
dial-up. I can try, but files that large usually don't make it - packet
corruption at some point probably.
 
D

Dianne Aldridge

Alrighty then -- here's all the code:

Dim StudentName As String
Dim HaveName As Boolean
Dim NumCorrect As Integer
Dim NumIncorrect As Integer
Dim QuizQuestion As Integer
Dim printableSlideNum As Long

Sub HideGoBackButtons()

'Hide all of the "Go Back to Quiz" buttons
ActivePresentation.Slides(2).Shapes("SL2Button").Visible = False
ActivePresentation.Slides(3).Shapes("SL3Button").Visible = False
ActivePresentation.Slides(4).Shapes("SL4Button").Visible = False
ActivePresentation.Slides(5).Shapes("SL5Q4Button").Visible = False

End Sub
Sub StartLesson()

MakeVisible
HideGoBackButtons

HaveName = False
While Not HaveName
StudentName = InputBox(prompt:="Please type your name in
the space below", Title:="Student Name")
If StudentName = "" Then
HaveName = False
Else
HaveName = True
' MsgBox (StudentName & ", don't forget to look at your
checklist to see where you need to begin studying.")
End If
Wend

ActivePresentation.SlideShowWindow.View.GotoSlide (2)

End Sub
Sub StartQuiz()

MakeVisible
ActivePresentation.Slides(5).Shapes("SL5HomeButton").Visible =
False

NumCorrect = 0
NumIncorrect = 0

printableSlideNum = ActivePresentation.Slides.Count + 1

HaveName = False
While Not HaveName
StudentName = InputBox(prompt:="Please type your name in
the space below", Title:="Student Name")
If StudentName = "" Then
HaveName = False
Else
HaveName = True
End If
Wend

ActivePresentation.SlideShowWindow.View.GotoSlide (10)

End Sub
Sub RightAnswerQuestion1()

NumCorrect = NumCorrect + 1
ActivePresentation.SlideShowWindow.View.Next

End Sub
Sub WrongAnswerQuestion1()

NumIncorrect = NumIncorrect + 1
ActivePresentation.SlideShowWindow.View.Next

End Sub
Sub GoBackQuestion1()

QuizQuestion = 1
ActivePresentation.SlideShowWindow.View.GotoSlide (2)

End Sub
Sub RightAnswerQuestion2()

NumCorrect = NumCorrect + 1
ActivePresentation.SlideShowWindow.View.Next

End Sub
Sub WrongAnswerQuestion2()

NumIncorrect = NumIncorrect + 1
ActivePresentation.SlideShowWindow.View.Next

End Sub
Sub GoBackQuestion2()

QuizQuestion = 2
ActivePresentation.SlideShowWindow.View.GotoSlide (2)

End Sub
Sub RightAnswerQuestion3()

NumCorrect = NumCorrect + 1
ActivePresentation.SlideShowWindow.View.Next

End Sub
Sub WrongAnswerQuestion3()

NumIncorrect = NumIncorrect + 1
ActivePresentation.SlideShowWindow.View.Next

End Sub
Sub GoBackQuestion3()

QuizQuestion = 3
ActivePresentation.SlideShowWindow.View.GotoSlide (2)

End Sub
Sub RightAnswerQuestion4()

NumCorrect = NumCorrect + 1
ActivePresentation.SlideShowWindow.View.Next

End Sub
Sub WrongAnswerQuestion4()

NumIncorrect = NumIncorrect + 1
ActivePresentation.SlideShowWindow.View.Next

End Sub
Sub GoBackQuestion4()

QuizQuestion = 4
ActivePresentation.SlideShowWindow.View.GotoSlide (2)

End Sub
Sub RightAnswerQuestion5()

NumCorrect = NumCorrect + 1
PrintablePage

End Sub
Sub WrongAnswerQuestion5()

NumIncorrect = NumIncorrect + 1
PrintablePage

End Sub
Sub GoBackQuestion5()

QuizQuestion = 5
ActivePresentation.SlideShowWindow.View.GotoSlide (2)

End Sub
Sub GoBack()
If QuizQuestion = 1 Then
ActivePresentation.SlideShowWindow.View.GotoSlide (10)
ElseIf QuizQuestion = 2 Then
ActivePresentation.SlideShowWindow.View.GotoSlide (11)
ElseIf QuizQuestion = 3 Then
ActivePresentation.SlideShowWindow.View.GotoSlide (12)
ElseIf QuizQuestion = 4 Then
ActivePresentation.SlideShowWindow.View.GotoSlide (13)
ElseIf QuizQuestion = 5 Then
ActivePresentation.SlideShowWindow.View.GotoSlide (14)
End If

End Sub
Sub PrintablePage()

Dim printableSlide As Slide
Dim exploreButton As Shape
Dim printButton As Shape

Set printableSlide =
ActivePresentation.Slides.Add(Index:=printableSlideNum, _
Layout:=ppLayoutText)
printableSlide.FollowMasterBackground = msoFalse
printableSlide.Background.Fill.ForeColor.RGB = vbWhite
printableSlide.Shapes(1).TextFrame.TextRange.Text = "Quiz Results
for " & StudentName
printableSlide.Shapes(2).TextFrame.TextRange.Text = _
StudentName & " completed the Radio lesson." & Chr$(13) & _
StudentName & " got " & NumCorrect & " out of 5 questions
correct." & Chr$(13) & _
StudentName & " earned a " & 100 * NumCorrect / (NumIncorrect +
NumCorrect) & "% on this quiz." & Chr$(13) & _
"Press the Print Results button to print your results for your
teacher, then go and explore more about the radio."
Set exploreButton = _
ActivePresentation.Slides(printableSlideNum).Shapes.AddShape _
(msoShapeActionButtonCustom, 400, 400, 150, 50)
exploreButton.TextFrame.TextRange.Text = "Go Explore"
exploreButton.Fill.ForeColor.RGB = vbBlue
exploreButton.ActionSettings(ppMouseClick).Action =
ppActionRunMacro
exploreButton.ActionSettings(ppMouseClick).Run = "GoExplore"
Set printButton = _
ActivePresentation.Slides(printableSlideNum).Shapes.AddShape _
(msoShapeActionButtonCustom, 150, 400, 150, 50)
printButton.TextFrame.TextRange.Text = "Print Results"
printButton.Fill.ForeColor.RGB = vbBlue
printButton.ActionSettings(ppMouseClick).Action = ppActionRunMacro
printButton.ActionSettings(ppMouseClick).Run = "PrintResults"
ActivePresentation.SlideShowWindow.View.Next
ActivePresentation.Saved = True

exploreButton.Name = "exploreButton"
printButton.Name = "printButton"

End Sub
Sub PrintResults()


ActivePresentation.Slides(printableSlideNum).Shapes("exploreButton").Visible
= False

ActivePresentation.Slides(printableSlideNum).Shapes("printButton").Visible
= False

ActivePresentation.PrintOptions.OutputType = ppPrintOutputSlides
ActivePresentation.PrintOut From:=printableSlideNum,
To:=printableSlideNum


ActivePresentation.Slides(printableSlideNum).Shapes("exploreButton").Visible
= True

ActivePresentation.Slides(printableSlideNum).Shapes("printButton").Visible
= True


End Sub
Sub GoExplore()

ActivePresentation.SlideShowWindow.View.GotoSlide (6)
ActivePresentation.Slides(printableSlideNum).Delete
ActivePresentation.Saved = True

End Sub
Sub MakeVisible()
Dim sld As Slide
Dim shp As Shape

For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
shp.Visible = True
Next shp
Next sld
End Sub

Sub GetOjbectName()

MsgBox (ActiveWindow.Selection.ShapeRange.Name)

End Sub
Sub SetObjectName()

Dim ObjectName As String

ObjectName = InputBox(prompt:="Type a name for the object")
ObjectName = Trim(ObjectName)
If ObjectName = "" Then
MsgBox ("You did not type anything. The name will remain " & _
ActiveWindow.Selection.ShapeRange.Name)
Else
ActiveWindow.Selection.ShapeRange.Name = ObjectName
End If

End Sub
 
B

Beverley

One thing you could try is insert:

StudentName = ""

Put this just before you start each of the two while loops that ask for and
check the name. It "shouldn't" make any difference, but then upon reviewing
your code it "shouldn't" be doing this anyway.

So it'll be something like:
HaveName = False
StudentName = ""
While Not HaveName
.....etc

Beverley
 
G

Guest

Dianne,

First, I believe I have solved the problem, and I believe that typing a web
address for a name has nothing to do with the problem, except that the type
of student who would type a web address instead of his name is the same type
of student who would do other things that would cause problems. This is
actually a good trait for a student because exploring is a good thing.

The simplest solution to your problem is to replace the line

ActivePresentation.SlideShowWindow.View.Next

in your PrintablePage procedure with:

ActivePresenation.SlideShowWindow.View.GotoSlide printableSlideNum

Here is what I am fairly sure is happening. Student X (for eXplorer) went
through the presentation and got to to the printable slide. Rather than click
on the GoExplore button, he hit Escape. At this point, before the Printable
Slide was deleted, the computer asked him if he wanted to save, and he said
yes. Why did it ask him if he wanted to save? Because things had changed in
the procedure since the last time you said to ActivePresentation.Saved =
True. These two lines, probably trigger ActivePresentation.Saved to be False
again:

exploreButton.Name = "exploreButton"
printButton.Name = "printButton"

Another simple solution would be to put ActivePresentation.Saved = True
after those two lines. In fact, I would do both of those simple things (the
one with GotoSlide and this one). This will prevent anyone from ever quitting
out of the presentation and being asked to save while the printable slide
still exists.

The first fix will give the added protection that if someone does somehow
save the presentation with a printable slide, they will never see that slide
because a new slide is being created, and when it is time to view the
printable slide, you go to the new slide and never to the old printable slide
if it even exists.

Let me know how this works for you.

--David

David Marcovitz
Microsoft PowerPoint MVP
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPoint/
 
D

Dianne Aldridge

David,
Boy, that masters in Computer Science sure does come in handy with this
stuff, doesn't it? :)

I understand completely your explanation and it makes perfect sense: He
wrote to the file by saving it making it a permanent change. I don't
know why, but I thought that you couldn't alter a .pps file, but
apparently when you use VBA you can; a printable slide is created
during the show, so yes, obviously you can.

I won't be at the elementary school for another week (for retention
testing), but I'll try the fix then and see if it works. I'm confident
it will - I'll be sure and let you know. I'll add the new code to all
of the lessons in my final product. And I'll be sure and thank Tristyn
the eXplorer for helping me tweak out my lessons.

P.S. I "sold" another one of your books today to a 3rd-grade student
teacher who considered himself a PP guru until he saw my VBA scripted
lessons. He quickly realized he has a lot to learn. Don't we
all............. :)

Thank you, David.
 
D

David M. Marcovitz

I'm glad it makes sense. Thanks for selling my books. I get that a lot.
Most people I talk to about the book have no idea that PowerPoint can do
all that.
--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top