Solved

Timer problem vb6

Posted on 2013-11-16
8
325 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
[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
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 47

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

729 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