Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select case - end select statement in a Timer 1

Status
Not open for further replies.

baconandeggs

Programmer
Dec 31, 2000
21
GB

baconandeggs (Programmer)
Jan 6, 2001
Hello everyone
Can anyone straighten me out on a Select Case Statement for a timer
Overview:
I have a form which has a circle crossed by 4 lines and filled bright yellow to resemble the SUN, a label asks for the correct passsword to be entered and a label to the right which has a yellow background say's [LIGHT ON] which pulses to the same time that the SUN pulses
Current code only pulses at 3 second intervals.
The criteria I am using is this:
Lightstate = 0 Light on for 3 seconds
Lightstate = 1 and 3 light off 1 second
Lightstate = 2 and 4 Light on for 1 second
Lightstate = 5 Light off 3 seconds
can you set the correct interval for the timer
best regards

Jim
[small]
'In the general declarations part of the Form Code window, DECLARE A VARIABLE
Dim LightState As Integer
Dim Kount As Integer
Private Sub cmdClose_Click()
Unload Me
'stop the timer
tmrLight.Enabled = False


'Reset integer variables
Kount = 0
LightState = 0
End
End Sub

Private Sub Form_Load()
Me.Caption = "PAOS " & "" & "James Kennedy " & "" & "20th December 2000 "

'make the signalling lamp components invisible on startup
ShpRay_1.Visible = False
ShpRay_2.Visible = False
ShpRay_3.Visible = False
ShpRay_4.Visible = False
ShpFlash.Visible = False

lblLight.Visible = False

Kount = 0

'Set initial Variable Value
LightState = 5

End Sub

Private Sub lblLight_Click()

End Sub

Private Sub tmrlight_Timer()


Kount = Kount + 1
lblSecondCount = Kount

Select Case LightState

Case 0

ShpRay_1.Visible = False
ShpRay_2.Visible = False
ShpRay_3.Visible = False
ShpRay_4.Visible = False
ShpFlash.Visible = False
lblLight.Visible = False
If Kount = 3 Then
ShpRay_1.Visible = True
ShpRay_2.Visible = True
ShpRay_3.Visible = True
ShpRay_4.Visible = True
ShpFlash.Visible = True
lblLight.Visible = True

txtPassword.Visible = True
txtPassword.BackColor = &HFFFFFF
txtPassword.SetFocus


Kount = 0
tmrLight.Enabled = True

End If
Case 1

If Kount = 0 Then

ShpRay_1.Visible = True
ShpRay_2.Visible = True
ShpRay_3.Visible = True
ShpRay_4.Visible = True
ShpFlash.Visible = True
lblLight.Visible = True
End If

If Kount = 1 Then

ShpRay_1.Visible = False
ShpRay_2.Visible = False
ShpRay_3.Visible = False
ShpRay_4.Visible = False
ShpFlash.Visible = False
lblLight.Visible = False


End If
If Kount > 2 Then

ShpRay_1.Visible = True
ShpRay_2.Visible = True
ShpRay_3.Visible = True
ShpRay_4.Visible = True
ShpFlash.Visible = True

txtPassword.Visible = True
txtPassword.BackColor = &HFFFFFF
txtPassword.SetFocus
tmrLight.Enabled = True
Kount = 0

End If

Case 2
If Kount = 0 Then

ShpRay_1.Visible = False
ShpRay_2.Visible = False
ShpRay_3.Visible = False
ShpRay_4.Visible = False
ShpFlash.Visible = False
lblLight.Visible = False

End If
If Kount = 1 Then

ShpRay_1.Visible = True
ShpRay_2.Visible = True
ShpRay_3.Visible = True
ShpRay_4.Visible = True
ShpFlash.Visible = True
lblLight.Visible = True

End If
If Kount > 2 Then

ShpRay_1.Visible = False
ShpRay_2.Visible = False
ShpRay_3.Visible = False
ShpRay_4.Visible = False
ShpFlash.Visible = False
lblLight.Visible = False

txtPassword.Visible = False
txtPassword.BackColor = &HFFFFFF
txtPassword.SetFocus

tmrLight.Enabled = False

Kount = 0


End If

Case 5


If Kount = 0 Then

ShpRay_1.Visible = True
ShpRay_2.Visible = True
ShpRay_3.Visible = True
ShpRay_4.Visible = True
ShpFlash.Visible = True

lblLight.Visible = True
End If

If Kount = 1 Then

ShpRay_1.Visible = False
ShpRay_2.Visible = False
ShpRay_3.Visible = False
ShpRay_4.Visible = False
ShpFlash.Visible = False

lblLight.Visible = False

End If
If Kount > 3 Then

ShpRay_1.Visible = True
ShpRay_2.Visible = True
ShpRay_3.Visible = True
ShpRay_4.Visible = True
ShpFlash.Visible = True

lblLight.Visible = True

txtPassword.Visible = True
txtPassword.BackColor = &HFFFFFF
txtPassword.SetFocus

tmrLight.Enabled = True
Kount = 0

End If

End Select

End Sub

Private Sub txtPassword_Change()
Dim I As Integer, num As Single

If txtPassword.Text = "nrg" _
Or txtPassword.Text = "Nrg" _
Or txtPassword.Text = "NRG" Then

'for the correct password use green as signal
txtPassword.BackColor = &HC000&
Else
If txtPassword.Text <> &quot;nrg&quot; _
Or txtPassword.Text <> &quot;Nrg&quot; _
Or txtPassword.Text <> &quot;NRG&quot; Then
'change the colour of the text to red as a signal but use hexadecimal

txtPassword.BackColor = &amp;HFF&amp;
End If

'set a 1 second delay
For I = 1 To 20000

'let the processor do some work

num = 10000 / 5000


Next

txtPassword.Text = &quot;&quot;
'hide txtpassword
txtPassword.Visible = True

'Show lblLight
lblLight.Visible = True
'start timer
tmrLight.Enabled = True
Exit Sub


End If

End Sub


[/small]
 
So, you want the light to blink in this pattern?

3 sec on
1 sec off
1 sec on
3 sec off

Try this:
[tt]
Option Explicit
Dim LightState As Integer

Private Sub cmdOff_Click()
LightState = 0
HandleLights
tmrLight.Enabled = false
End Sub

Private Sub cmdOn_Click()
LightState = 1
HandleLights
End Sub

Private Sub HandleLights()
Select Case LightState
Case 0: 'all lights off, no timer
tmrLight.Enabled = False
light.Visible = False

Case 1: 'starting 3 sec on period
tmrLight.Interval = 3000
tmrLight.Enabled = True
LightState = 2
light.Visible = True

Case 2: 'starting 1 sec off period
tmrLight.Interval = 1000
LightState = 3
light.Visible = False

Case 3: 'starting 1 sec on period
tmrLight.Interval = 1000
LightState = 4
light.Visible = True

Case 4: 'starting 3 sec off period
tmrLight.Interval = 3000
LightState = 1
light.Visible = False

End Select
End Sub

Private Sub tmrLight_Timer()
HandleLights
End Sub
[/tt]

Hope this helps.
Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top