Forum Discussion

mdh's avatar
mdh
Contributor
8 years ago

UserForm - how to start a test if there si no action in userform?

I have a small userform with a START button, which when pressed creates a mdOK, which then triggers a test to be run.

 

Now, if the START is NOT pressed for like 20 seconds, I still want the test to start anyway (using some default settings), how do I do that ?

 

 

3 Replies

    • mdh's avatar
      mdh
      Contributor

      Thanks, tried below (VBS)... but doesn't really work, the sub are never called.

       

      But if using this format:  Set Timer1 = Utils.Timers.Add(10000, TimerTest.TimerRoutine, True) - the TimerRoutine is called, but without any delay.. what's wrong...

       

      ------_ EXAMPLE --------

      The script name is = TimerTest

       

      Sub Main
        Dim Timer1

        Call Log.Message("Main ......started ...")
        Set Timer1 = Utils.Timers.Add(10000, "TimerTest.TimerRoutine", True)

        Call Log.Message("Main ......COMPLETED")
      End Sub

       

      Sub TimerRoutine
        Call Log.Message("TimerRoutine was started ...")
      End Sub

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        The time part of the timer object is not a delay, it's a frequency.  In other words, it will execute TimerTest.TimerRoutine every 10 seconds.  So, your code creates the timer, it executes once, and then you end your function which ends the test run.

        What I would suggest is you do the Utils.Timers.Add on the OnShow event handler of your user form.  That event handler should do a couple of things:

         

        1) Create the timer with the set interval

        2) Assign the timer to some globally accessible variable

        3) Mark a date/time stamp of when the form was first shown, also in something globally accessible.

         

        The timer routine that you add to the timer should do two things:

         

        1) Check to see if the status of the form is mdOK

        2) If it's not mdOK, check the time from when the form was first shown.  If it is more than 20 seconds, hide the form and fire off the tests with the desired defaults.

        Finally, in the forms OnHide event handler, you need to add code to set the Enabled status of the timer object to false.