Solved

Timer problem vb6

Posted on 2013-11-16
8
315 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 45

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

760 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

23 Experts available now in Live!

Get 1:1 Help Now