Jadilah Anggota smaneka untuk mendapatkan informasi terkini di smaneka.tk, yuk...

Guru Welly

Foto saya
NIP. 197812312010011028 / NUPTK 0563756657110173 / N.R.G 162241136461 / Nomor Peserta Sertifikasi Pendidik 16051822410077 / Kode Sertifikasi 224

Kamis, 07 Mei 2009

VB : TrafficLight Skrip


Tugas ditulis diselembar kertas, diberi nama/kelas, dikumpulkan dimeja guru lab komputer. Boleh menggunakan lab komputer diatas.
1. Buatlah flowchart dan analisa tentang bagaimana program ini mengalir dan bekerja ?
2. Hasil yang akan terjadi bila skrip VB ini dieksekusi adalah ?

Tugas ditulis diselembar kertas, diberi nama/kelas, dikumpulkan dimeja guru lab komputer. Boleh menggunakan lab komputer diatas.
1. Buatlah flowchart dan analisa tentang bagaimana program ini mengalir dan bekerja ?
2. Hasil yang akan terjadi bila skrip VB ini dieksekusi adalah ?
 
'the following constants are used to give the lights a certain color
Const Off = &H8000000F
Const Red = vbRed
Const Green = vbGreen
Const 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 = 5
Const TimeForStatus2 = 3
Const TimeForStatus3 = 5
Const TimeForStatus4 = 3

Private Sub SetStatus(ByVal intStatus As Integer)
  'Set the status variable to the new status
  Status = intStatus

  'Turn off all the lights
  shpLamp1Groen.FillColor = Off
  shpLamp1Oranje.FillColor = Off
  shpLamp1Rood.FillColor = Off
  shpLamp2Groen.FillColor = Off
  shpLamp2Oranje.FillColor = Off
  shpLamp2Rood.FillColor = Off
  shpLamp3Groen.FillColor = Off
  shpLamp3Oranje.FillColor = Off
  shpLamp3Rood.FillColor = Off
  shpLamp4Groen.FillColor = Off
  shpLamp4Oranje.FillColor = Off
  shpLamp4Rood.FillColor = Off
   
  'Turn on the appropriate lights with the correct color,
  'depending on the current status
  Select Case intStatus 'or "Select Case Status", won't make any difference
  Case 1
  shpLamp1Rood.FillColor = Red
  shpLamp2Groen.FillColor = Green
  shpLamp3Rood.FillColor = Red
  shpLamp4Groen.FillColor = Green
   
  Timer1.Interval = TimeForStatus1 * 1000
  Case 2
  shpLamp1Rood.FillColor = Red
  shpLamp2Oranje.FillColor = Orange
  shpLamp3Rood.FillColor = Red
  shpLamp4Oranje.FillColor = Orange
   
  Timer1.Interval = TimeForStatus2 * 1000
  Case 3
  shpLamp1Groen.FillColor = Green
  shpLamp2Rood.FillColor = Red
  shpLamp3Groen.FillColor = Green
  shpLamp4Rood.FillColor = Red
   
  Timer1.Interval = TimeForStatus3 * 1000
  Case 4
  shpLamp1Oranje.FillColor = Orange
  shpLamp2Rood.FillColor = Red
  shpLamp3Oranje.FillColor = Orange
  shpLamp4Rood.FillColor = Red
   
  Timer1.Interval = TimeForStatus4 * 1000
  End Select
   
  'We need to call the following subroutine
  RefreshLights
End Sub

Private Sub RefreshLights()
  'This subroutine makes sure that de data on the screen is
  'displayed correctly
  shpLamp1Groen.Refresh
  shpLamp1Oranje.Refresh
  shpLamp1Rood.Refresh
  shpLamp2Groen.Refresh
  shpLamp2Oranje.Refresh
  shpLamp2Rood.Refresh
  shpLamp3Groen.Refresh
  shpLamp3Oranje.Refresh
  shpLamp3Rood.Refresh
  shpLamp4Groen.Refresh
  shpLamp4Oranje.Refresh
  shpLamp4Rood.Refresh
End Sub

Private Sub Form_Load()
  'When the programs starts, it starts with status 1
  SetStatus 1
  'Initializing the timer will start the timer1_timer subroutine after the
  'set interval has elapsed (in milliseconds)
  Timer1.Interval = TimeForStatus1 * 1000
End Sub
Private Sub Timer1_Timer()
  'Change to the next status
  Status = Status + 1
  'If the next status is 5 then we need to change it back to one
  If Status = 5 Then Status = 1
   
  SetStatus Status
End Sub


Sumber : planetsourcecode.com



Tidak ada komentar:

 
Minima 4 coloum Blogger Template by Beloon-Online.
Simplicity Edited by Ipiet's Template