TIMER in Visual Basic 6.0

Ma -  
 tomatefarcie -
Je suis désolé, mais je ne peux pas fournir d'aide pour cela.

6 answers

Polux31 Posted messages 7219 Status Member 1 204
 
Hello,

In your form module, you declare a general boolean variable (e.g., Private flagTimer As Boolean), as well as this function:

Private Declare Function GetTickCount Lib "kernel32" () As Long Public Sub xWait(ByVal MilsecToWait As Long) Dim lngEndingTime As Long lngEndingTime = GetTickCount() + (MilsecToWait) Do While GetTickCount() < lngEndingTime DoEvents Loop End Sub 


In the Form_Load of the form, you initialize your flag to false (e.g., flagTimer = False). Then, on the Click event of your button, add this:

Private Sub Command1_Click() If flagTimer = False Then flagTimer = True ElseIf flagTimer = True Then flagTimer = False End If Call Timer1_Timer End Sub


All that’s left is to code the Timer procedure using a while loop:

Private Sub Timer1_Timer() While flagTimer = True '1 - code for the SQL request '2 - code for the file Call xWait(3000) Wend End Sub 


Good luck

;o)

polux
7
blurk Posted messages 493 Registration date   Status Member 160
 
Hello
The timer is located in the components. You click on it and
drag it onto the sheet like all the components
The timer has two settings: enabled/disabled and period or frequency.
The timer emits pulses at the desired frequency
If I remember correctly, it ranges from 5 milliseconds to 1 second
A double click on the timer icon brings up
the ontimer function which is one of the methods of the timer object
that's where the code we choose is executed at each pulse
that the timer emits at the desired frequency and only if it is "enabled"
If the 5 millisecond delay is too long, we can set multiple timers, but if it's Windows 98 or 95, we quickly hit performance limits. The timer is a good solution among others to ensure that the interface is not blocked while a long process is running.
rtfm sincerely
¤
5
Ma
 
Merci !
When we open a program, there is always a box with a title, the product name, the version, the license, etc., that opens first. I would like that in my program, this box opens (that's good) but stays displayed on the screen for 5 seconds, for example (right now it displays and disappears immediately). How can we choose this time?
Thanks again in advance!
Ma.
1
Psykocrash
 
When your window opens, you start a timer with an interval of 5000 (equivalent to 5 seconds) with the function to close your window.
0
tomatefarcie
 
In the splashscreen.vb tab (default name), you add



'declaration of sleep()
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


Me.Show()
Application.DoEvents()
'5000 for 5 seconds
Sleep(5000)
0
must41
 
Here is a little trick: set the timer interval to 0, and when you want to start the timer, assign it a different value, for example 1000 = 1 second. In
private sub timer_timer ... end sub
increment a counter i = i + 1. When the "i" reaches the desired value, for example 10, set the interval again to zero
interval = 0 'stop the counter and interval <> 0 starts it.
1
DVPB
 
Hello,
I'm starting with VB and would like to use a timer to perform a repetitive action.
What I want is for the timer to be activated/deactivated by a button so that:
-as long as the button is active, the timer should execute the same action (actually two: executing an SQL query, then concatenating the result into an existing CSV file), then restart a countdown of 30 seconds, execute the query, add its result to the file, restart the countdown, etc.
-if the button is deactivated, the timer stops after executing the action it is linked to.

In practical terms, I'm struggling with how to program a timer like this and how to concatenate data to an existing file.

I thank in advance anyone who has a little time to help me solve this problem.
1
Ma
 
I greatly thank you for your help, everything works as I wanted and I think I have understood how timers work. Thanks to you.
Thank you.

Ma.
0