1 Replies - 668 Views - Last Post: 19 June 2014 - 11:46 PM Rate Topic: -----

#1 MrTimothy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-June 14

VB6 Timer Loop for Relay control

Posted 19 June 2014 - 09:39 PM

Ok ..Here is my problem,.. I'm very new at VB6 .. like I just started 5 days ago.. My first program is all completed except for a timer loop. I have 2 timers..1 start button ..1 stop button.. 2 text boxes were I enter times.. My First countdown timer and text box 1 is a "SPAN" in time .. The second timer and text box 2 is a "DURATION OF TIME" so it works like this.. I enter the amount of time .. lets say the span time is 3 minutes .. and the duration time is 5 minutes. I click start and it counts down in text box 1 ..when text box 1 hits zero it turns on a relay and starts counting down in text box 2 .. when text box 2 hits zero the relay turns off.

but what I need is a way to loop it.. a way that it will do this countdown continuously until i stop the loop with the stop button.

as of right now everything is working other than the loop.. I hope someone can help.. Pleas don't mind the other buttons.. they are for manually switching the relays. also there maybe some dead code .. like I said I've only been doing this a week and have tried many things. hope someone can help..

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Call SetRelays(1, True)
End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Call SetRelays(1, False)
End Sub

Private Sub Command3_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Call SetRelays(2, True)
End Sub

Private Sub Command3_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Call SetRelays(2, False)
End Sub

Private Sub Command5_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Call SetRelays(2, False)
End Sub

Private Sub Command6_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Call SetRelays(1, False)
End Sub

Private Sub Command7_Click()
Timer1.Interval = 1000
    Timer1.Enabled = True
    If Text1 = 0 Then
    Timer1.Enabled = False
    
    End If
    Timer2.Enabled = False
    Call SetRelays(2, False)
    Call SetRelays(1, False)
      
   End Sub

Private Sub Command8_Click()
Timer1.Enabled = False
Timer2.Enabled = False
Call SetRelays(2, False)
Call SetRelays(1, False)

End Sub

Private Sub Form_Terminate()
    FT_Close (lnghandle)
End Sub

Private Sub Command1_Click()
 Call SetRelays(1, True)
End Sub

Private Sub Command2_Click()
Call SetRelays(1, False)
Call SetRelays(2, False)
End Sub


Private Sub Command3_Click()
Call SetRelays(2, True)
End Sub

Private Sub Command4_Click()
Call SetRelays(2, False)
Call SetRelays(1, False)
End Sub

Private Sub Command5_Click()
Call SetRelays(1, True)
End Sub

Private Sub Command6_Click()
Call SetRelays(2, True)
End Sub

Private Sub Form_load()
RelState = 0
If FT_Open(0, lnghandle) <> FT_OK Then
    Status.Caption = "Error while opening"
    Exit Sub
Else
    
End If

If FT_SetBitMode(lnghandle, 255, 4) <> FT_OK Then
    Status.Caption = "Bit Bang Mode Error"
    Exit Sub
Else
    
End If

If FT_SetBaudRate(lnghandle, 921600) <> FT_OK Then
    Status.Caption = "Baudrate setting error"
    Exit Sub
Else
    Status.Caption = "USB Dome Control Relay Board Opened and Ready"
End If
Timer1.Enabled = False
Timer2.Enabled = False
Dim iTime As Integer
End Sub

Private Sub List1_Click()
If TextBox1.Text = "" And TextBox2.Text = "" Then
    ListBox1.Items.Add ("Some Text")
    End If
End Sub

Private Sub Text1_Change()
 If Not IsNumeric(Text1.Text) Then
     Text1.Text = ""
     End If

End Sub

Private Sub Text2_Change()
 If Not IsNumeric(Text2.Text) Then
     Text2.Text = ""
 End If

End Sub

Private Sub Timer1_Timer()
 If IsNumeric(Text1) Then Text1 = Text1 - 1
    If Text1 = 0 Then
        Timer1.Enabled = False
        Timer2.Enabled = True
        Call SetRelays(2, True)
                        
                        End If
        
        End Sub
  

Private Sub Timer2_Timer()
If IsNumeric(Text2) Then Text2 = Text2 - 1
    If Text2 = 0 Then
        Timer2.Enabled = False
        Call SetRelays(2, False)
        
        End If
End Sub
        


This post has been edited by macosxnerd101: 19 June 2014 - 09:55 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: VB6 Timer Loop for Relay control

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

Re: VB6 Timer Loop for Relay control

Posted 19 June 2014 - 11:46 PM

The simplest way would be to re-enable the first timer (and associated countdown variables) when the second timer has timed out.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1