Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Timer problem vb6

Posted on 2013-11-16
8
Medium Priority
?
340 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 2000 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 49

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:isnoend2001
ID: 39653500
Must have copied something wrong. thanks
0
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

885 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