Kamis, 28 Mei 2009


'the following constants are used to give the lights a certain colorConst Off = &H8000000FConst Red = vbRedConst Green = vbGreenConst Orange = &H80C0FF'a simple traffic junction of two perpendicular crossing streets'consists of 4 traffic poles. Each traffic pole has a green, orange'and red light. There is always just one light on per pole.'The traffic lights control on one of those junctions has just 4'statusses. The current status is stored in the variable "Status".Dim Status As Integer'The time a status lasts, is derived from the following constants, which'indicate the time in seconds.Const TimeForStatus1 = 5Const TimeForStatus2 = 3Const TimeForStatus3 = 5Const TimeForStatus4 = 3Private Sub SetStatus(ByVal intStatus As Integer)'Set the status variable to the new statusStatus = intStatus'Turn off all the lightsshpLamp1Groen.FillColor = OffshpLamp1Oranje.FillColor = OffshpLamp1Rood.FillColor = OffshpLamp2Groen.FillColor = OffshpLamp2Oranje.FillColor = OffshpLamp2Rood.FillColor = OffshpLamp3Groen.FillColor = OffshpLamp3Oranje.FillColor = OffshpLamp3Rood.FillColor = OffshpLamp4Groen.FillColor = OffshpLamp4Oranje.FillColor = OffshpLamp4Rood.FillColor = Off'Turn on the appropriate lights with the correct color,'depending on the current statusSelect Case intStatus 'or "Select Case Status", won't make any differenceCase 1shpLamp1Rood.FillColor = RedshpLamp2Groen.FillColor = GreenshpLamp3Rood.FillColor = RedshpLamp4Groen.FillColor = GreenTimer1.Interval = TimeForStatus1 * 1000Case 2shpLamp1Rood.FillColor = RedshpLamp2Oranje.FillColor = OrangeshpLamp3Rood.FillColor = RedshpLamp4Oranje.FillColor = OrangeTimer1.Interval = TimeForStatus2 * 1000Case 3shpLamp1Groen.FillColor = GreenshpLamp2Rood.FillColor = RedshpLamp3Groen.FillColor = GreenshpLamp4Rood.FillColor = RedTimer1.Interval = TimeForStatus3 * 1000Case 4shpLamp1Oranje.FillColor = OrangeshpLamp2Rood.FillColor = RedshpLamp3Oranje.FillColor = OrangeshpLamp4Rood.FillColor = RedTimer1.Interval = TimeForStatus4 * 1000End Select'We need to call the following subroutineRefreshLightsEnd SubPrivate Sub RefreshLights()'This subroutine makes sure that de data on the screen is'displayed correctlyshpLamp1Groen.RefreshshpLamp1Oranje.RefreshshpLamp1Rood.RefreshshpLamp2Groen.RefreshshpLamp2Oranje.RefreshshpLamp2Rood.RefreshshpLamp3Groen.RefreshshpLamp3Oranje.RefreshshpLamp3Rood.RefreshshpLamp4Groen.RefreshshpLamp4Oranje.RefreshshpLamp4Rood.RefreshEnd SubPrivate Sub Form_Load()'When the programs starts, it starts with status 1SetStatus 1'Initializing the timer will start the timer1_timer subroutine after the'set interval has elapsed (in milliseconds)Timer1.Interval = TimeForStatus1 * 1000End SubPrivate Sub Timer1_Timer()'Change to the next statusStatus = Status + 1'If the next status is 5 then we need to change it back to oneIf Status = 5 Then Status = 1SetStatus StatusEnd Sub

Tidak ada komentar:

Posting Komentar