Consulting

Results 1 to 14 of 14

Thread: Powerpoint calculation

  1. #1

    Powerpoint calculation

    Helloo everyone, i am new here. And I do not have any experience with vab, I need help with some coding please i have a powerpoint game with 40 slides each slide has a points counter I used an active x lable for theses there are two counters per slide. the counters are named Label 11 and Lable 12 The end slide is number 41 and i have a scoreboard in it all i want to do is to display the total number of points in the scoreboard for Lable 11 And Lable 12 so basically just adding up all the points i have added a png of the scoreboard I hope someone can help
    Attached Images Attached Images

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,133
    Location
    Welcome to VBAX William4728. I have moved your thread to the Powerpoint section, hopefully you will get some assistance here.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    You can place the variables for the total boys and girls scores in a module, when increasing or decreasing it on each slide's total also do it to these public variables, this will make the values available to the last slide to display it there.

    Module1
        Public totalBoysScore as Integer
        Public totalGirlsScore as Integer

  4. #4
    Quote Originally Posted by jdelano View Post
    You can place the variables for the total boys and girls scores in a module, when increasing or decreasing it on each slide's total also do it to these public variables, this will make the values available to the last slide to display it there.

    Module1
        Public totalBoysScore as Integer
        Public totalGirlsScore as Integer

    Hi thank you for your reply but it does not work, Maybe i was not clear on what I need. I also send you pictures of the slide and total slide and the code i am using to change the points on each slide.

    All I require is for lable 11 and Label 12 to show the grand total of points for all the slides and display it in the scoreboard


    Here is the code i am using to change the points in each slide

    Sub Label1Plus1()
        Label1.Caption = (Label1.Caption) + 1
    End Sub
    
    Sub Label1Minus1()
        Label1.Caption = (Label1.Caption) - 1
    End Sub
    
    Sub Label2Minus1()
        Label2.Caption = (Label2.Caption) - 1
    End Sub
    
    Sub Label2Plus1()
        Label2.Caption = (Label2.Caption) + 1
    End Sub
    
    Sub Label1Reset()
        Label1.Caption = 0
    End Sub
    
    Sub ExitPPT()
        ActivePresentation.SlideShowWindow.View.Exit
    End Sub
    
    Sub Reset()
        Label1.Caption = 0
        Label2.Caption = 0
    End Sub
    
    
    Private Sub Label1_Click()
    
    End Sub
    
    
    Private Sub Label2_Click()
    
    End Sub
    as i have indicated in the picture scoreboard
    Attached Images Attached Images

  5. #5
    In the code where you do plus or minus, you need to add the totalBoysScore = totalBoysScore + 1 or totalBoysScore = totalBoysScore - 1 (same with the girls score) then you use the amounts in these variables to fill the last slide.

  6. #6
    I have tried your surggestion but it does not do what I want it to do, It only allows me to increase or decrese the points by a factor of +/- 1 I already have that part working. All I need is to total Slide 1 to 40 Label 11 and show this figure in the Scoreboard and the same for Label 12

  7. #7
    If each slide increases (or decreases depending on what is needed) the global total variable as well as its own, then the global variable will be a sum of all slides.
    An alternative would be to loop though all slides and read the label values.

    You could insert a Module and create:
    Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)
    
        Dim totalBoysScore As Integer
        Dim totalGirlsScore As Integer
    
    
        Dim sld As Slide
        Dim shp As Shape
        
        For Each sld In ActivePresentation
            
            For Each shp In sld.Shapes
                If shp.Name = "Label11" Then
                    
                    If sld.Name = "Slide41" Then
                        ' this is the last slide, put the totals in the labels
                        shp.TextFrame.TextRange.Text = totalBoysScore
                    Else
                        totalBoysScore = totalBoysScore + Val(shp.TextFrame.TextRange.Text)
                    End If
                    
                ElseIf shp.Name = "Label12" Then
                
                    If sld.Name = "Slide41" Then
                        ' this is the last slide, put the totals in the labels
                        shp.TextFrame.TextRange.Text = totalGirlsScore
                    Else
                        totalGirlsScore = totalGirlsScore + Val(shp.TextFrame.TextRange.Text)
                    End If
                                
                End If
            Next shp
        Next sld
    
    
    
    End Sub
    This event runs every time a slide is, well, changed during the presentation. This isn't completely tested just trying to give an alternate idea

  8. #8
    Thank you for your help, so I add this code to a new module or add it to my existing code if the later does it go at the begining or the end and do I have to add the code to all the slides sorry to be a pain just no great understanding of VBA

  9. #9
    You can put this in any Module file (those listed under the Modules section on the left project pane)
    No worries, this stuff can be tough to get your head around, especially this event as it isn't documented.

  10. #10
    Hi Jdelano, I have tried to get this to work over the weekend but nothing happens If i make a video clip of how my slides work showing you how it is set up. Will this site allow to up load it to you maybe I am doing something wrong, I put the code in a new module and also tried adding to the existing code nothing happens.

  11. #11
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,133
    Location
    You can always try to attach a PPT to your post. Click on Go advanced, Manage Attachments and follow the prompts from there.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  12. #12
    I just tried to upload the ppt file I keep fetting the error cant upload the file ppt.

  13. #13
    Ok I have shortened the file because it was too big but in the original file there are 41 slides with 41 being the scoreboard
    Attached Images Attached Images
    Attached Files Attached Files

  14. #14
    Thanks, I just about have it sorted.

    EDIT:
    Okay, I added Module1 (as previously described) then added the global variables for girl's and boy's totals. Then I added a public sub procedure that updates both the totals in the vars, and the total displayed in the labels on Slide41; there weren't any labels for the scores on that slide, so I added a label1 and label2 by copying them from another slide.

    Code in Module1
    ' global variable holding thee total points
    Public totalBoysScore As Integer
    Public totalGirlsScore As Integer
    
    
    Public Sub AdjustTotals(whichOne As String, UpOrDown As String)
    
    
        ' adjust the global variables accordingly
        Select Case whichOne
        
            Case "Girls"
                If UpOrDown = "Up" Then
                    totalGirlsScore = totalGirlsScore + 1
                Else
                    totalGirlsScore = totalGirlsScore - 1
                End If
            Case "Boys"
                If UpOrDown = "Up" Then
                    totalBoysScore = totalBoysScore + 1
                Else
                    totalBoysScore = totalBoysScore - 1
                End If
        
        End Select
        
        ' write the total to the proper labels on slide41
        Dim lastSlide As Slide
        Set lastSlide = ActivePresentation.Slides(ActivePresentation.Slides.Count)
        
        ' because the shape is actually an ActiveX label, you have to
        ' access the caption property which is different from a normal shape
        lastSlide.Shapes("Label1").OLEFormat.Object.Caption = totalGirlsScore
        lastSlide.Shapes("Label2").OLEFormat.Object.Caption = totalBoysScore
        
        Set lastSlide = Nothing ' release the slide object
    End Sub
    I modified the code in Slide1 (start), Slide2 and Slide 3

    Slide1: I changed the start action to a Macro to reset all score labels to 0 as well as the global vars
    Sub ResetAllScores()
        ' on start reset all score labels to 0 and the global variables that hold the totals
        Dim sld As Slide
        
        ' the first slide doesn't have label1 and 2 - ignore the error that they aren't there
        On Error Resume Next
        For Each sld In ActivePresentation.Slides
        
            ' because the shape is actually an ActiveX label, you have to
            ' access the caption property which is different from a normal shape
            
            sld.Shapes("Label1").OLEFormat.Object.Caption = 0
            sld.Shapes("Label2").OLEFormat.Object.Caption = 0
        
        Next sld
    
    
        On Error Resume Next
        
        totalGirlsScore = 0
        totalBoysScore = 0
    
    
        SlideShowWindows(1).View.Next   ' move to the next slide
        
    End Sub

    Slide2 and 3 have similar code so I'll just show Slide2 modifications
    Sub Label1Plus1()
        Label1.Caption = (Label1.Caption) + 1 ' increase the girls score for this slide
        AdjustTotals "Girls", "Up" ' increase the girls score for the last slide
    End Sub
    Sub Label1Minus1()
        Label1.Caption = (Label1.Caption) - 1 ' decrease the girls score for this slide
        AdjustTotals "Girls", "Down" ' decrease the girls score for the last slide
        
    End Sub
    Sub Label2Minus1()
        Label2.Caption = (Label2.Caption) - 1 '  decrease the boys score for this slide
        AdjustTotals "Boys", "Down" ' decrease the boys score for the last slide
        
    End Sub
    Sub Label2Plus1()
        Label2.Caption = (Label2.Caption) + 1 ' increase the girls score for this slide
        AdjustTotals "Boys", "Up" ' increase the boys score for the last slide
    End Sub
    Now, you could clean this up more by just calling AdjustTotals and send a reference to the label on the slide, that way you would just call AdjustTotals and it would handle all the scoring needs, but I didn't want to get too far into the weeds.
    Attached Files Attached Files
    Last edited by jdelano; 05-20-2024 at 02:40 AM.

Posting Permissions

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