vb5, using the timer to show a form

xdanad
xdanad used Ask the Experts™
on
Hi,

I have a vb5 program which makes use of 5 forms.

I require one of my forms called data_display to load and be shown every 90 seconds.
This form needs to be held open for 10 seconds before unloading.

I gather this can be done using the timer event in vb.

However I have never used the timer before so don’t really know where to start.

Any ideas on how I can solve my problem.

Many Thanks,

xdanad
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
place a timer control on your form, and set it's interval to 30000 (ie 30 seconds).
declare a variable intTimerCount as integer in your form
set the timer's enabled property to true
in the timer's Timer event, place some code like this:
  intTimerCount = intTimerCount + 1
  if intTimerCount >=3 then
    'show the other form
    Form2.show
    intTimerCount = 0
  endif


In the other form (form2), also place a timer, interval = 10000 (ie 10 seconds), enabled = true, and the timer code:
  unload me

The form2's load even could hold the code to load the data to be displayed...

CHeers

Commented:
Assuming you have a main form called frmMain -

Add two timer controls to frmMain, Timer1 and Timer2.
Set Timer1 interval = 90000
Set Timer2 Interval = 10000

Add the following code to frmMain:

Private Sub Timer1_Timer()
data_display.Show
Timer1.Enabled = False
Timer2.Enabled = True
End Sub

Private Sub Timer2_Timer()
data_display.Hide
Timer2.Enabled = False
Timer1.Enabled = True
End Sub

Or, if you need the form_load & unload events to fire:

Private Sub Timer1_Timer()
Load data_display
Timer1.Enabled = False
Timer2.Enabled = True
End Sub

Private Sub Timer2_Timer()
Unload data_display
Timer2.Enabled = False
Timer1.Enabled = True
End Sub

But, the 2nd way is slower.

Commented:
Oops! 90000 is too big a value for Timer Interval.

Instead, do something like Angel suggested:

Set Timer1 Interval to 10000
Then...

Private Sub Timer1_Timer()

Static Counter As Integer

Counter = Counter + 1
   If Counter >= 9 Then
   Load data_display
   Timer1.Enabled = False
   Timer2.Enabled = True
   Counter = 0
End if

End Sub

Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Thanks for the help so far.

Is there a way to ‘globally’ set the timer.

Adding the timer controls to the main form assumes that the main form will always be shown and loaded.

There are a few occasions where the main form is unloaded. With one of the other forms being shown instead.
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
Commented:
I assume that you have always 1 "main" form shown?
Anyway, the timer control needs 1 form, which doesn't need to be visible, thus you could create a "TimerForm", which only contains the timer control...

Cheers
Commented:
Sure, but it would require the data_display form to always be loaded.

Just put the two timers on it and put the timer event code in it.  One timer shows it, the other hides it.
If you need to fire data_display's load and unload events, simply call them like this:

Private Sub Timer1_Timer()

Static Counter As Integer

Counter = Counter + 1
  If Counter >= 9 Then
  data_display.show
  Call data_display.Form_Load
  Timer1.Enabled = False
  Timer2.Enabled = True
  Counter = 0
End if

End Sub

Private Sub Timer2_Timer()

data_display.hide
Call data_display.Form_Unload
Timer2.Enabled = False
Timer1.Enabled = True

End Sub

Commented:
Oops again! That should be:

Call data_display.Form_Unload(False)

Author

Commented:
Thank you both for your help. I'll split the points between you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial