Consulting

Results 1 to 6 of 6

Thread: Retaining a variable for 2nd or third execution of macro

  1. #1
    VBAX Newbie
    Joined
    Nov 2017
    Location
    Ballarat, Australia
    Posts
    4
    Location

    Retaining a variable for 2nd or third execution of macro

    I have created a slide which shows club photos and sponsors rolling along sides and bottom. and now want to use that slide to do a raffle draw. I have done it successfully with userform but its appearance on the slide is a bit clunky.
    the basic process is
    click on a text box -has a 0 displayed on the slide.
    message box is displayed to enter start number
    message box is displayed to enter the last number
    textbox now shows winning number - from random generator
    operator now clicks again for redraw if not claimed or for second or third prize.

    in code below the second (or third time through) results in 1 as the number displayed not a new random generated number as Endvalue = 1. (On the userform I kept the EndValue in a another textbox that was hidden)
    I would also want to set the displayed text back to 0 at the end or between the draw from 1st to subsequent other draws (I will add an End) command button could I do that then?)

    Sub UpdateRandomNumber(oSh As Shape)
    Dim X As Long
    Dim EndValue As Integer
    Dim StartValue As Integer
    Dim Message, Title, Default
    Dim MyValue As Integer
         ' Start Number
    If oSh.TextFrame.TextRange.Text = "0" Then
       Message = "Enter Raffle Start Number"    ' Set prompt.
       Title = "Raffle Start Number"    ' Set title.
       Default = "1"    ' Set default.
       StartValue = InputBox(Message, Title, Default)
        ' End Number
       Message = "Enter Raffle End Number"    ' Set prompt.
       Title = "Raffle End Number"    ' Set title.
       Default = "12"    ' Set default.
       EndValue = InputBox(Message, Title, Default)
    '  As a test Display dialog box at position 100, 100.
    MyValue = InputBox(Message, Title, EndValue, 100, 100)
    End If
    X = EndValue  ' How do I get end value to = what was entered on ist time through?
    oSh.TextFrame.TextRange.Text = CStr(Random(X))
    SlideShowWindows(1).View.GotoSlide (SlideShowWindows(1).View.Slide.SlideIndex)
    ' Do it again as a test
    SlideShowWindows(1).View.GotoSlide (SlideShowWindows(1).View.Slide.SlideIndex)
    oSh.TextFrame.TextRange.Text = CStr(Random(X))
    'Now force PPT to go to the slide again (ie, to redraw it) so that
    'the changed text appears:
    SlideShowWindows(1).View.GotoSlide (SlideShowWindows(1).View.Slide.SlideIndex)
    End Sub
    Function Random(High As Long) As Long
    'Generates a random number less than or equal to
    'the value passed in High
    Randomize
    Random = Int((High * Rnd) + 1)
    End Function
    Last edited by Paul_Hossler; 11-24-2017 at 05:42 PM.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    1. Welcome to VBX

    2. I added CODE tags around your macro to set it off and for formatting - you can use the [#] icon next time

    3. It'd probably be easier if you could upload a small PP with enough slide to demonstrate what you want to do

    Otherwise people will have to create a PP and make sure shape names, etc. are correct

    My sig has instructions
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Newbie
    Joined
    Nov 2017
    Location
    Ballarat, Australia
    Posts
    4
    Location

  4. #4
    VBAX Newbie
    Joined
    Nov 2017
    Location
    Ballarat, Australia
    Posts
    4
    Location
    Paul, Thanks for setting me straight on the editing etc

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    raffle draw basic with macro (1).pptmThis shows how to use Pseudo Event OnSlideShowPageChange to reset variables. NOTE there is a hidden command button on slide 1 top left. This has no code but is essential if the event code is to be reliable.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    VBAX Newbie
    Joined
    Nov 2017
    Location
    Ballarat, Australia
    Posts
    4
    Location
    Thanks John I can complete it now.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •