You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

IAO

Beginner

  • "IAO" is male
  • "IAO" started this thread

Posts: 38

Date of registration: May 25th 2013

Location: Venezuela

Occupation: Electronic

  • Send private message

1

Thursday, July 11th 2013, 7:44pm

Problem with Timer1 and Timer2 (RESOLVED)

Hi

I have a problem with Timer1-2 running at the same time.
Timer1 should run first, at the end Timer1, Timer2 should run.

Sometimes Timer1 does not run. Direct jumps Timer2

I have two days doing tests and I can not see what's wrong.
In VB6 this works well..

Put 2 timer, 1 label, 1 buttom

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Dim i As Integer , g As Integer 

Public Sub Command1_Click()
   Timer1.Enabled = True
   Timer1.Interval=400

   'MsgBox  "See Problem"    '*<=== Uncomment to see how it work.
   
   Timer2.Enabled = True
   Timer2.Interval=500
   Label1.ForeColor = vbRed 
End Sub

Public Sub Timer1_Timer()
    i=i+1  
    If i >= 10 Then 
      Timer1.Enabled=False 
    End If   

    Label1.Caption =  "Change Test Leads : " + i 
    'Label1.Refresh 
    'DoEvents
     
End Sub

Public Sub Timer2_Timer()
    g=g+1
    If  g >= 10 Then
      Timer2.Enabled=False
    End If     
  
    Label1.Caption = "Wait a Moment : " + g
    'Label1.Refresh 
    'DoEvents
    
End Sub


I hope someone can help. ;(
Thanks in advance. :)

This post has been edited 4 times, last edit by "IAO" (Jul 12th 2013, 2:07am)


IAO

Beginner

  • "IAO" is male
  • "IAO" started this thread

Posts: 38

Date of registration: May 25th 2013

Location: Venezuela

Occupation: Electronic

  • Send private message

2

Friday, July 12th 2013, 1:51am

Hi....

I think this solved my problem. The program is working as I wanted.

Put 2 timer(Timer1 and Timer2, 1 Label, 1 Buttom controls in form designer.

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Private Winapi Function Sleep Lib "Kernel32.dll" (ByVal aTime As Integer)

Dim i As Integer,  g As Integer 

Public Sub Command1_Click()
   Timer1.Interval=400
   Timer1.Enabled = True
   g=10

  Do
  '***Yield to other programs 
  '***(better than using DoEvents which eats up all the CPU cycles)
    Sleep 100
    DoEvents
  Loop Until i >= 10


   Timer2.Interval=500   
   Timer2.Enabled = True
   Label1.ForeColor = vbRed 
End Sub

Public Sub Timer1_Timer()
    i=i+1  
    If i >= 10 Then 
      Timer1.Enabled=False 
    End If   

    Label1.Caption =  "Change Test Leads : " + i 
     
End Sub

Public Sub Timer2_Timer()
    g=g-1
    If  g <= 1 Then
      Timer2.Enabled=False
    End If     
  
    Label1.Caption = "Wait a Moment : " + g
    
End Sub


I hope this can help others.
Greetings and best wishes. :thumbsup:


.

This post has been edited 5 times, last edit by "IAO" (Jul 12th 2013, 2:02am)


Rate this thread
WoltLab Burning Board