PDA

View Full Version : Perform calculation based on shape selection



tolanio
01-08-2021, 10:24 PM
Hello there. I need some help with this macros. I am trying to capture the scores from the text display on a shape and add it to another shape upon clicking a shape. I am trying to do this when in presentation mode. Here is what i have so far. Thank you

Sub addTeamScores(oshp As Shape)
Dim score, TeamAScore, TeamBScore As Double


Set osld = ActivePresentation.SlideShowWindow.View.Slide

score = CDbl(ActivePresentation.Slides(slideNum).Shapes("ScoreBoard").TextFrame.TextRange.Text)
TeamAScore = CDbl(ActivePresentation.Slides(slideNum).Shapes("Score1").TextFrame.TextRange.Text)
TeamBScore = CDbl(ActivePresentation.Slides(slideNum).Shapes("Score2").TextFrame.TextRange.Text)

Select Case oshp.Name
Case "Add1"
Call addScore(score, TeamAScore)
Case "Add2"
Call addScore(score, TeamBScore)
End Select

End Sub


Private Sub addScore(i As Double, j As Double)
j = j + i
i = 0
End Sub

John Wilson
01-10-2021, 08:57 AM
See if this gets you started

Sub addTeamScores(oshp As Shape)

Dim score As Long, TeamAScore As Long, TeamBScore As Long
Dim osld As Slide
Set osld = ActivePresentation.SlideShowWindow.View.Slide


'there will be an error if box is not a number
If Not IsNumeric(osld.Shapes("ScoreBoard").TextFrame.TextRange) Then _
osld.Shapes("ScoreBoard").TextFrame.TextRange.Text = "0"
If Not IsNumeric(osld.Shapes("Score1").TextFrame.TextRange) Then _
osld.Shapes("Score1").TextFrame.TextRange.Text = "0"
If Not IsNumeric(osld.Shapes("Score2").TextFrame.TextRange) Then _
osld.Shapes("Score2").TextFrame.TextRange.Text = "0"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
score = CLng(osld.Shapes("ScoreBoard").TextFrame.TextRange.Text)
TeamAScore = CLng(osld.Shapes("Score1").TextFrame.TextRange)
TeamBScore = CLng(osld.Shapes("Score2").TextFrame.TextRange)
Select Case oshp.Name
Case "Add1"
osld.Shapes("Score1").TextFrame.TextRange.Text = CStr(TeamAScore + score)
Case "Add2"
osld.Shapes("Score2").TextFrame.TextRange.Text = CStr(TeamBScore + score)
End Select
End Sub

bobbyrfletch
01-17-2021, 03:22 AM
Thanks