Results 1 to 13 of 13

Thread: how to make a toggle button that light up

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,887
    Location
    Sorry, but I really got lost with the overall flow, and all of the redundant / duplicated code

    A simplified the 4 'Activates' and 2 of the 8 'Clicks'

    Since there appears to be some consistency with the names of the shapes, this could be make even more general

    Typically, something like this would have a 'database' (probably an array) of what is shown for each button


    Option Explicit
    Sub ActivateLevelDC()
        Call pvtPickupApply("flameDC", 8)
        Call pvtPickupApply("GasdetectorDC", 14)
        Call pvtPickupApply("H2SdetectorDC", 4)
    End Sub
    Sub ActivateLevelD1()
        Call pvtPickupApply("flameD1", 8)
        Call pvtPickupApply("GasdetectorD1", 7)
        Call pvtPickupApply("H2SdetectorD1", 3)
    End Sub
    Sub ActivateLevelCC()
        Call pvtPickupApply("flameCC", 8)
        Call pvtPickupApply("GasdetectorCC", 14)
        Call pvtPickupApply("H2SdetectorCC", 4)
    End Sub
    Sub ActivateLevelC1()
        Call pvtPickupApply("flameC1", 8)
        Call pvtPickupApply("GasdetectorC1", 4)
        Call pvtPickupApply("H2SdetectorC1", 4)
    End Sub
    
    Private Sub pvtPickupApply(sShapeName As String, iShapeCount As Long)
        Dim i As Long
            
        With ActivePresentation.Slides(1)
            For i = 1 To iShapeCount
                .Shapes(sShapeName & i & "-2").PickUp
                .Shapes(sShapeName & i).Apply
            Next I
        End With
    End Sub

    and


    Option Explicit
    Sub pltC_2_Click()
        Call pvtShowShapes("pltC-2", "knapCC-2", "knapC1-2")
        Call pvtHideShapes("pltD-2", "knapDC-2", "knapD1-2", "levelCC-2", "levelC1-2", "levelDC-2", "levelD1-2")
        Call pvtPresets("knapC-2", "knapD-2")
    End Sub
    
    
    Sub pltD_2_Click()
        Call pvtShowShapes("pltD-2", "knapDC-2", "knapD1-2")
        Call pvtHideShapes("pltC-2", "knapCC-2", "knapC1-2", "levelCC-2", "levelC1-2", "levelDC-2", "levelD1-2")
        Call pvtPresets("knapD-2", "knapC-2")
    End Sub
     
    
    Private Sub pvtPresets(sShapeName40 As String, sShapeName41 As String)
        With ActivePresentation.Slides(1).Shapes(sShapeName40)
            .ShapeStyle = msoShapeStylePreset40
            .TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0)
        End With
        With ActivePresentation.Slides(1).Shapes(sShapeName41)
            .ShapeStyle = msoShapeStylePreset41
            .TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 255)
        End With
    End Sub
    
    Private Sub pvtShowShapes(ParamArray aShapes() As Variant)
        Dim i As Long
        
        For i = LBound(aShapes) To UBound(aShapes)
            ActivePresentation.Slides(1).Shapes(aShapes(i)).Visible = True
        Next i
    End Sub
    
    Private Sub pvtHideShapes(ParamArray aShapes() As Variant)
        Dim i As Long
        
        For i = LBound(aShapes) To UBound(aShapes)
            ActivePresentation.Slides(1).Shapes(aShapes(i)).Visible = False
        Next I
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    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

Posting Permissions

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