Reloj Digital:
Private Sub Form_Load()
TmrM.Enabled = False
TmrH.Enabled = False
LblP1.Caption = ""
LblP2.Caption = ""
End Sub
Private Sub TmrS_Timer()
LblS.Caption = LblS.Caption + 1
If LblS.Caption Mod 2 = 0 Then
LblP1.Caption = ""
LblP2.Caption = ""
ElseIf LblS.Caption Mod 2 <> 0 Then
LblP1.Caption = ":"
LblP2.Caption = ":"
End If
If LblS.Caption = 59 Then
TmrM.Enabled = True
LblS.Caption = 0
End If
End Sub
Private Sub TmrM_Timer()
If TmrM.Enabled = True Then
LblM.Caption = LblM.Caption + 1
TmrM.Enabled = False
If LblM.Caption = 59 Then
LblM.Caption = 0
End If
End If
End Sub
Es de tomar en cuenta que:
- Los numeros del reloj van a ir en Labels. También los dos puntos que los separan.
- Lbl es el prefijo de Label.
- LblS es el prefijo del Label de los segundo, LblM para minutos y LblH para las horas.
- Tmr es el prefijo de Timer.
- TmrS es el Timer de los segundos, TmrM para minutos y TmrH para las horas.
- LblP1 y LblP2 son los Labels de los dos puntos.
- El intervalo(Interval) que se le asignará a TmrS en la Ventana de Propiedades es 1000.
- El interval que se le asignará a TmrM y TmrH va a ser de 50 y Enabled=False para estos dos.
- LblP1 y LblP2 tendrán en la propiedad Caption esto ":" .
- LblS, LblM y LblH tendrán en Caption el valor 0, y la Alineación (Alignment) en Center.
Este es el código del semáforo:
Private Sub Form_Initialize()
ShpV.BackColor = vbGreen
TmrV.Enabled = True
TmrA.Enabled = False
TmrR.Enabled = False
TmrWin.Enabled = False
Label1.Visible = False
Label2.Visible = False
End Sub
Private Sub TmrV_Timer()
If TmrV.Enabled = True Then
TmrBlack.Enabled = True
TmrBlue.Enabled = True
End If
If TmrV.Interval = 3000 Then
ShpV.BackColor = vbBlack
TmrV.Enabled = False
TmrA.Enabled = True
End If
ShpA.BackColor = vbYellow
End Sub
Private Sub TmrA_Timer()
If TmrA.Interval = 1000 Then
ShpA.BackColor = vbBlack
TmrA.Enabled = False
TmrR.Enabled = True
End If
ShpR.BackColor = vbRed
TmrWin.Enabled = True
End Sub
Private Sub TmrR_Timer()
If TmrR.Interval = 3000 Then
ShpR.BackColor = vbBlack
TmrR.Enabled = False
TmrV.Enabled = True
End If
ShpV.BackColor = vbGreen
BlackCar.Left = 0
BlueCar.Left = 0
End Sub
Private Sub TmrBlack_Timer()
If ShpV.BackColor = vbGreen Then
BlackCar.Left = BlackCar.Left + 55
BlueCar.Left = BlueCar.Left + 36
End If
If ShpA.BackColor = vbYellow Then
BlueCar.Left = BlueCar.Left + 7
End If
End Sub
Private Sub TmrWin_Timer()
If ShpR.BackColor = vbRed Then
Label1.Visible = True
Label2.Visible = True
Label1.Top = Label1.Top + 8
Label2.Top = Label2.Top + 8
End If
If ShpV.BackColor = vbGreen Then
Label1.Visible = False
Label2.Visible = False
Label1.Top = 1560
Label2.Top = 1920
End If
End Sub
Diseño:
- La calle, las líneas blancas, la línea cuadriculada, el rectángulo amarillo del semáforo y los tres círculos que tiene el semáforo son todos objetos Shape, su prefijo será Shp.
- ShpV, ShpA, ShpR son los tres círculos del semáforo; verde, amarillo y rojo respectivamente.
- Habrán tres objetos Timer(Tmr), uno para cada Shp del semáforo. Estos Timers se llamarán TmrV, TmrA, y TmrR las ShpV, ShpA y ShpR respectivamente.
- Al ejecutarse el programa el ShpV tiene que estar en verde y los demás en negro.
- Las propiedades que tendrán que cambiar en los objetos ShpV, ShpA y ShpR serán: Shape:Circle, BackStyle:Opaque.
- La propiedad Interval de TmrV y TmrR será igual a 3000.
- La propiedad Interval de TmrA será igual a 1000.
FIN DE CLASE VII.

2 comentarios:
hola porfavor ayudeme;
tengo que hacer 3 vias de semaforo, con cronometro y que cuando los semaforos cambien de color parpadeen. gracias.
hola porfavor ayudeme;
tengo que hacer 3 vias de semaforo, con cronometro y que cuando los semaforos cambien de color parpadeen. gracias.
Publicar un comentario