dynamicaly setting events

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • questionit
    Contributor
    • Feb 2007
    • 553

    dynamicaly setting events

    Hi experts

    i want to set an event at runtime. I could'nt do it successfully so far.

    The purpose is to set Form's OnTimer event on a button click.

    [code=vb]
    Private Sub Command35_Click ()
    Me.Form.OnTimer = myFunc()
    End Sub

    Public Function myFunc() As Variant
    'Return a string with all the code statements in it ????
    'How to accomplish it ? what data type should be returned ?
    End Function

    [/code]

    Thanks
    Qi
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by questionit
    Hi experts

    i want to set an event at runtime. I could'nt do it successfully so far.

    The purpose is to set Form's OnTimer event on a button click.

    [code=vb]
    Private Sub Command35_Click ()
    Me.Form.OnTimer = myFunc()
    End Sub

    Public Function myFunc() As Variant
    'Return a string with all the code statements in it ????
    'How to accomplish it ? what data type should be returned ?
    End Function

    [/code]

    Thanks
    Qi
    1. Place the Function call within the Form's Timer() Event
      [CODE=vb]Private Sub Form_Timer()
      Dim retVal As Function Return Value
      retVal = fYourFunction()
      End Sub[/CODE]
    2. Manipulate the Interval between Function calls, and if the Function evens executes via the TimerInterval Property for the Form
      [CODE=vb]Me.TimerInterva l = 3000 'Function will run every 3 seconds (in milliseconds)
      Me.TimerInterva l = 0 'disables the Timer[/CODE]

    Comment

    • questionit
      Contributor
      • Feb 2007
      • 553

      #3
      Hi ADezii

      Thanks !

      The code is fine but i want to set the Form_Timer event only on a button click.

      I cant call the Form_Timer on a button click!

      The requirement was if i click the button, then it would start the timer.

      What do i need for this?

      Qi










      Originally posted by ADezii
      1. Place the Function call within the Form's Timer() Event
        [CODE=vb]Private Sub Form_Timer()
        Dim retVal As Function Return Value
        retVal = fYourFunction()
        End Sub[/CODE]
      2. Manipulate the Interval between Function calls, and if the Function evens executes via the TimerInterval Property for the Form
        [CODE=vb]Me.TimerInterva l = 3000 'Function will run every 3 seconds (in milliseconds)
        Me.TimerInterva l = 0 'disables the Timer[/CODE]

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by questionit
        Hi ADezii

        Thanks !

        The code is fine but i want to set the Form_Timer event only on a button click.

        I cant call the Form_Timer on a button click!

        The requirement was if i click the button, then it would start the timer.

        What do i need for this?

        Qi
        questionit, you are not listening! You manipulate the Timer() Event through the TimerInterval Property. To turn it OFF, set the TimerInterval = 0, to initialize the Event, set the TimerInterval to a non-zero value in milliseconds.

        Comment

        • questionit
          Contributor
          • Feb 2007
          • 553

          #5
          Thats fine ADezii

          Just for understanding , i wanted more clarification because i thought we could also easily initlialize and uninitialize Form_Timer event !!

          It would be handy if we can also change the functions on button click e.g:

          On Button 1 Click: Form_Timer = Function1
          On Button 2 Click : Form_Timer = Function2

          Thanks for the answer, it is helpful.

          Qi



          Originally posted by ADezii
          questionit, you are not listening! You manipulate the Timer() Event through the TimerInterval Property. To turn it OFF, set the TimerInterval = 0, to initialize the Event, set the TimerInterval to a non-zero value in milliseconds.

          Comment

          Working...