Passing a value between slides/modules

E

Emma Hope

Hi,

I have this scenario, i have a number of slides with buttons that the user
can click, enter a value and then i work out a new value in VBA and show it
on the slide.

To do this, i do "Call WorkingOutSub" on the click event of the button and
all my Subs are on Module1 as there is a lot of repetion.

My problem is, on Slide 2, i want to put three Buttons, GBP, EUR & USD, when
one is clicked, it gives the field strCurrency the value "GBP", "EUR" or
"USD" etc.

Then i want to bring this value to Module1, so i can do something like if
strCurrency = "GBP", "£".....blah blah......

But when i try to do this, my field strCurrency is empty, what i am doing
wrong, how can i get this value from the slide to my Module.

I've only been doing VBA for a little while, so please can you give
examples, not just 'declare your variable' etc as i won;t know what it means.

Thanks
Emma
 
D

David Marcovitz

Emma,

It might help if you post some code and let us know what version of
PowerPoint you have.

If you have all your code in Module1, that is a good thing. I know you
said not to tell you to declare your variables, but I am going to tell
you to do that. Every variable that you use should be declared, probably
at the very top of the module. That is, the first lines of your module
should be such things as:

Dim strCurrency as String
Dim otherVariable as Long
Dim yourMother as Variant

That way, every procedure in the module will know about those variables
and be able to access and change their content.

Now you want a button to affect the value of the variable strCurrency.
This can be done in several ways. One way to do it is to have three
procedures, one for each of your buttons. The GBP procedure would look
something like this (this is untested air code so there might be errors):

Sub GBPButton()
strCurrency = "GBP"
End Sub

Make one of these procedures for each button, link the buttons to the
correct procedures, and that should do it. Next you can have some other
button (even on another slide) that does something with the information
in strCurrency. For example:

Sub WhatsMyString()
If strCurrency = "GBP" Then
msgBox "Great Balls of Pyre"
ElseIf strCurrency = "EUR" Then
msgBox "EUR? I hardly know her"
ElseIf strCurrency = "USD" Then
msgBox "Underwater Submarine Day"
Else
msgBox "Nothing in strCurrency"
End If
End Sub

There are lots of other ways to do this, and if you are trying to do
more sophisticated things, there are lots of ways to do those, but this
should get you started.

--David
 

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