Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

VBA help with variables

A topic by Lex created Dec 02, 2019 Views: 313 Replies: 1
Viewing posts 1 to 2

Hello all, I'm new to programming with VBA and come from a background of simple codes in Python and HTML.

What I'm trying to do: Make a numeric variable that changes based on the choices (buttons) chosen.
Then, the value of the variable(s) determines the end slides. Also a way to dynamically display this variable would be great for testing.

I've been trying to wrap my head around this variable idea by using the info here: http://www.pptfaq.com/.

From my limited understanding, this variable will need to be global so that it can be changed at any point of the presentation. There might be multiple global variables that can change.
Also, the button that contains the trigger (what I know as "If-Else"), will also need to have some code in it that. An example is the button says "When this button is clicked, if variable1 >= 3, go to slide 3, else go to slide 5".

I've been able to get a variable using a modified version of the code found here: http://www.pptfaq.com/FAQ00583_Keep_Score_with_Static_Variables.htm

The example above uses a MsgBox to display the variable, which is a pop-up window that shows the text and score. I want the variable to only show as text for testing purposes, which I think I somewhat achieved using a shape named "TextBox" and mixing the code from the example:

Sub Example_Change()
With ActivePresentation.Slides(5).Shapes("TextBox")
  .TextFrame.TextRange.Text = "Your score is now " & CStr(AddToScore(0))
End With
End Sub

However, to get this to show the variable's number, the macro needs to be run inside of Visual Basic; I don't know how to execute the macro in a way that automatically updates the shape's text with this code. I also don't know how to change the value, as the increment code doesn't execute properly.

Any help with this would be greatly appreciated! Thanks in advance. :)

(+2)

If I understand your first issue, you want to be able to run this code. You should be able to assign your macro to an action button (Insert > Shapes > Select an Action button down the bottom).  Then when you run the presentation you should be able to click on the button and that will run your code. That's not the only way to do it but I believe that would be the simplest.

To confirm, this code should be placed on one of your modules (most likely called Module1) in the Visual Basic editor, as opposed to against a particular slide. That may be obvious but, since you're new to VBA, I thought it was worth making sure.

In case it's helpful, I've attached a simple Powerpoint Example of how to do the things you mentioned.  I've tried to keep it as straightforward as possible. Keep in mind you will need to enable editing and enable macros to run this.

Please let me know if this isn't what you're looking for or if you have any questions.