Hi,
I have a query in VB.
I have two forms.
The first form loads after few seconds my second form has to load.
How do I code for this.
Someone help me out.
Thanks,
Priya

Dani AI

Generated

A concise, practical set of options for based on the suggestions from , and . The most reliable approach in VB5 is to let the first form run normally and trigger the second form after a short delay, taking care not to block the UI thread.

A straightforward implementation (recommended): place a Timer control on Form1, enable it at startup, and in the timer handler disable it and show Form2. Load Form2 can be used beforehand to run any initialization without displaying the window.

Private Sub Form_Load()
    Timer1.Interval = 3000   ' 3000 = 3 seconds
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Timer1.Enabled = False
    Load Form2
    Form2.Show
    ' Unload Me    ' uncomment to close Form1 if desired
End Sub

Alternatives and cautions:

  • Avoid calling the OS Sleep function on the UI thread; it freezes the interface. If a busy-wait is needed, use a short DoEvents loop with GetTickCount, but this is less elegant than a timer.
  • Disable the timer in the handler to prevent repeated triggers.
  • Use Form2.Show vbModal if the second form must block interaction with others.
  • For heavy initialization, call Load Form2 early so the visible show is instant. Use Unload Form2 to free resources when done.
  • If the app is busy doing startup work, timer events may be delayed; keep heavy work off the UI thread during the wait.

These points expand the earlier replies and cover common pitfalls when delaying display of a second form in VB5.

Recommended Answers

All 5 Replies

Let them load whenever they want, only make the second form visible little later by elasping some time using a timer in the load event of the first one.

you want from2 like splashscreen?

Thanks for your idea to use Timer.
Let em give a try and get back to you
Thanks,
Priya

You call the second form in the timer event of timer control .Timer accepts interval in miliseconds . i.e. for 1 second u need to pass 1000.

or you can use delay()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.