• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1712
  • Last Modified:

Delay Action Using Timer

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
jonlake
Asked:
jonlake
1 Solution
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
I would probably use SLEEP 3 in the splash screen form
0
 
jonlakeAuthor Commented:
Sorry, but where do I put 'SLEEP 3' in the splash screen form?
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Yes, in the "form_Load" area.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Lee W, MVPTechnology and Business Process AdvisorCommented:
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
 
jonlakeAuthor Commented:
I get a compile error saying 'sleep' is not a recognised function.
0
 
bingieCommented:
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
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
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
 
jonlakeAuthor Commented:
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
 
ShauliCommented:
'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
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
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
 
jonlakeAuthor Commented:
Success!!! I never thought I'd get it - Thanks to everyone (particularly Shauli)

Jon
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now