?
Solved

Delay Action Using Timer

Posted on 2005-04-02
11
Medium Priority
?
1,710 Views
Last Modified: 2007-11-27
Hi, I am new to VB and have the following code opening my app. I want the splash screen to stay visible for 3 seconds before opening frmMain. Please let me know the best way to do this.

Sub Main()
    Dim fLogin As New frmLogin
    fLogin.Show vbModal
    If Not fLogin.OK Then
        'Login Failed so exit app
        End
    End If
    Unload fLogin


    frmSplash.Show
    frmSplash.Refresh
    Set fMainForm = New frmMain
    Load fMainForm
    Unload frmSplash


    fMainForm.Show
End Sub

Thanks

Jon
0
Comment
Question by:jonlake
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 13689755
I would probably use SLEEP 3 in the splash screen form
0
 

Author Comment

by:jonlake
ID: 13689797
Sorry, but where do I put 'SLEEP 3' in the splash screen form?
0
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 13689803
Yes, in the "form_Load" area.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 13689809
Actually, remove the "Unload frmSplash" from SubMain.

Then put in the form load part of the splash form:

sleep 3
Unload me

(I'll admit, I'm not 100% certain of this - I've done a fair amount of VB programming, but I don't recall if Sleep was an included command).  Try it.  If you get an error let me know.
0
 

Author Comment

by:jonlake
ID: 13689818
I get a compile error saying 'sleep' is not a recognised function.
0
 
LVL 11

Expert Comment

by:bingie
ID: 13689820
Sleep is a windows API function, which you need to declare at the top of your form:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Then,

SLEEP 1000 ' 1 second delay
0
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 13689836
Then SLEEP was not migrated from old Quickbasic as so many other commands were.  I didn't use it much to begin with, but with an object-oriented language such as VB, I'm not terribly surprised it wasn't an included function.  I imagine bingie's comment should solve the issue.
0
 

Author Comment

by:jonlake
ID: 13689871
I'll have to take some classes or something. I simply have no idea how to put the suggested code 'at the top of my form'. Thanks anyway, I'll try not to bother you guys again until I've learnt a little more.

Jon
0
 
LVL 19

Accepted Solution

by:
Shauli earned 200 total points
ID: 13689883
'locate a timer on frmSplash

Sub Main()
    Dim fLogin As New frmLogin
    fLogin.Show vbModal
    If Not fLogin.OK Then
        'Login Failed so exit app
        End
    End If
    Unload fLogin

    frmSplash.Show
    frmSplash.Refresh
    Set fMainForm = New frmMain
 
    fMainForm.Show
End Sub

'in frmSplash form copy the below and paste
Private Sub Timer1_Timer()
Unload frmSplash
Timer1.Enabled = False
End Sub

Private Sub Form_Load()
Timer1.Interval = 3000 '3 seconds, 1000 = 1 second so modify accordingly
Timer1.Enabled = True
End Sub

S
0
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 13689886
On the splash form, look at the code.  then at the very top of the page, put bingie's code.  (Above any "Sub" statements)
0
 

Author Comment

by:jonlake
ID: 13689969
Success!!! I never thought I'd get it - Thanks to everyone (particularly Shauli)

Jon
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question