Solved

Timer problem vb6

Posted on 2013-11-16
8
317 Views
Last Modified: 2013-11-16
I am not experienced using a timer i am trying to pause a procedure a number of second passed
Private Sub Command1_Click()
Chill 10
End Sub


Sub Chill(seconds As Integer)
Dim i As Integer
Dim counter As Integer
seconds = seconds * 1000
Timer2.Interval = 1000
Timer2.Enabled = True
For i = 1 To seconds Step 1000
counter = counter + 1000
Next i
 Command1.Visible = False
Timer2.Enabled = False
End Sub
What is the problem. the above code does not work. it fires immediately
0
Comment
Question by:isnoend2001
8 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 39653484
You cannot use the timer to pause as such.

When you start the timer, it will fire a Timer event after the interval has elapsed and you need to put some code in the event to do what you want to do after the interval. This will hide the Command button for a second.

Option Explicit

Private Sub Command1_Click()
    Command1.Visible = False
    Chill 10
End Sub


Sub Chill(seconds As Integer)
    Timer2.Interval = 1000
    Timer2.Enabled = True
End Sub

Sub Timer2_Timer()
    Command1.Visible = True
    Timer2.Enabled = False
End Sub

Open in new window

0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39653487
Just do
' At the top of your form
Declare Sub Sleep Lib "kernel32" (ByVal milliseconds As Long)

and then
Sleep 10000 ' Time in miliseconds
0
 

Author Comment

by:isnoend2001
ID: 39653494
thanks  MartinLiss, but i have been using sleep, but don't want the app to freeze

Thanks  GrahamSkan, but it does not work
0
 

Author Closing Comment

by:isnoend2001
ID: 39653500
Must have copied something wrong. thanks
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:QuinnDex
ID: 39653501
this line is not needed

Timer2.Enabled = True

' Visual Basic 6.0
Public Function TimerOn(Interval As Integer)
   If Interval > 0 Then
      Timer1.Interval = Interval   ' Enables the timer.
   Else
      Timer1.Interval = 0         ' Disables the timer.
   End If
End Function

Open in new window

0
 

Author Comment

by:isnoend2001
ID: 39653525
Modified it to just pass the seconds:
Public Sub Chill(seconds As Integer)
  seconds = seconds * 1000
    Timer2.Interval = seconds '1000
    Timer2.Enabled = True
End Sub
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39653534
That should work.

However, in complex program situations there could be a danger of confusing yourself when a variable called seconds is also used for milliseconds.
0
 

Author Comment

by:isnoend2001
ID: 39653544
thanks GrahamSkan i will keep that in mind
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Opening Remote & Local Data Connection 2 52
Restricting text box entry from \/:?<>"| 9 77
Windows 10 start screen issues 9 52
VB6 Compile Compatibility Issue 4 90
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now