Consulting

Results 1 to 14 of 14

Thread: Powerpoint calculation

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #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
  •