dcsimg
Results 1 to 3 of 3

Thread: How to pass object name to Timer1

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2004
    Posts
    52

    How to pass object name to Timer1

    How can i use a single Timer sub for different picture/image objects? My code works fine for a specified image, but i can't figure how to pass any image object name to the Timer2 sub, instead of hard-coding the specific image name (eg: Image1(6)?

    Code:
    Public Sub Timer2_Timer()
    With Image1(6)
            If .Width < maxpicwidth And .Height < maxpicheight Then
                NewWidth = .Width + 300! 
                NewHeight = NewWidth * HeightKeep / WidthKeep
                'Move left, top, width, height
               .Move .Left - 150!, .Top, NewWidth, NewHeight
            Else
                Timer2 = False
                .Enabled = True
            End If
        End With
    End Sub
    /Jimboat

  2. #2
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,514

    Re: How to pass object name to Timer1

    The Timer control's .Tag property can be used to store any arbitrary string.

    Another option would be to use a module level variable, so something like this:

    Code:
    Private mo_TimerControl As Object
    
    Private Sub Picture1_Click()
       Set mo_TimerControl = Me.Picture1
    End Sub
    
    Private Sub Picture2_Click()
       Set mo_TimerControl = Me.Picture2
    End Sub
    
    Public Sub Timer2_Timer()
       If Not mo_TimerControl Is Nothing
        With mo_TimerControl
            If .Width < maxpicwidth And .Height < maxpicheight Then
                NewWidth = .Width + 300! 
                NewHeight = NewWidth * HeightKeep / WidthKeep
                'Move left, top, width, height
               .Move .Left - 150!, .Top, NewWidth, NewHeight
            Else
                Timer2 = False
                .Enabled = True
            End If
        End With
       End If 
    End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2004
    Posts
    52

    Re: How to pass object name to Timer1

    jpbro - works like a charm! Thanks for the solution!
    /Jimboat

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width