h1

Hufhh Capek

Desember 13, 2009

dah capek ne nyariin adek tercinta source code vb 6 traffic light, mbak pulang dulu y dek

h1

Traffic Light (3)

Desember 13, 2009

‘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

h1

Traffic Light (2) Buat Vita yang sok rajin ha..ha

Desember 13, 2009

Option Explicit
Dim counter As Integer

Private Sub Command1_Click()
counter = counter + 1
If counter = 5 Then
counter = counter – 4
End If
If counter = 1 Then
shpRed.BackColor = RGB(255, 0, 0)
shpAmber.BackColor = RGB(255, 255, 255)
shpGreen.BackColor = RGB(255, 255, 255)
ElseIf counter = 2 Then
shpAmber.BackColor = RGB(210, 100, 45)
ElseIf counter = 3 Then
shpGreen.BackColor = RGB(0, 140, 0)
shpRed.BackColor = RGB(255, 255, 255)
shpAmber.BackColor = RGB(255, 255, 255)
ElseIf counter = 4 Then
shpGreen.BackColor = RGB(255, 255, 255)
shpAmber.BackColor = RGB(210, 100, 45)
End If
End Sub

Private Sub Form_Load()
counter = 1
shpRed.BackColor = RGB(255, 0, 0)
shpAmber.BackColor = RGB(255, 255, 255)
shpGreen.BackColor = RGB(255, 255, 255)
End Sub

and this one is for the timer controlled program:

Option Explicit
Dim counter As Integer

Private Sub Command1_Click()
Timer1.Enabled = True
End Sub

Private Sub Form_Load()
counter = 1
shpRed.BackColor = RGB(255, 0, 0)
shpAmber.BackColor = RGB(255, 255, 255)
shpGreen.BackColor = RGB(255, 255, 255)
End Sub

Private Sub Timer1_Timer()
counter = counter + 1
If counter = 5 Then
counter = counter – 4
End If
If counter = 1 Then
shpRed.BackColor = RGB(255, 0, 0)
shpAmber.BackColor = RGB(255, 255, 255)
shpGreen.BackColor = RGB(255, 255, 255)
ElseIf counter = 2 Then
shpAmber.BackColor = RGB(210, 100, 45)
ElseIf counter = 3 Then
shpGreen.BackColor = RGB(0, 140, 0)
shpRed.BackColor = RGB(255, 255, 255)
shpAmber.BackColor = RGB(255, 255, 255)
ElseIf counter = 4 Then
shpGreen.BackColor = RGB(255, 255, 255)
shpAmber.BackColor = RGB(210, 100, 45)
End If
End Sub

To set the timer to an interval of 1000 open your form, select the timer
(which I assume you have placed on the form) then at the right of the screen
you can set the interval to 1000. Let me know how you get on.
PS. if you’re gonna use my coding then remember to use the same names for
your lights i.e. shpGreen, shpRed, shpAmber

h1

Traffic Light (1) Buat Vita Programmer Gadungan

Desember 13, 2009

Best Answer – Chosen by Asker
The only thing i’m not sure of is how to make TAB activate the lights. But, this is what you have to do:

1. Lay out the 3 picture boxes.
2. Use “BackColor” to fill them in ( start with just green)
3. Make a timer
4. Under the timer make a counter and then an if statement to reset the counter after 4 loops. Then make 3 if statements, one for each counter (1,2,3). Under each “if”, put the next lights fillcolor and hide the other two. Repeat this pattern

Sample

—Ne Codenya–

Dim Counter As Single
Private Sub Timer1_Timer()
Counter = Counter + 1
If Counter = 4 Then
Counter = 1
End If
If Counter = 1 Then
Picture1.BackColor = &HC000&
Picture2.BackColor = vbWhite
Picture3.BackColor = vbWhite
End If
If Counter = 2 Then
Picture2.BackColor = &HFFFF&
Picture1.BackColor = vbWhite
Picture3.BackColor = vbWhite
End If
If Counter = 3 Then
Picture3.BackColor = vbRed
Picture1.BackColor = vbWhite
Picture2.BackColor = vbWhite
End If

End Sub

h1

Buat Bapak,Ibu dan Vita

Desember 9, 2009

Tetap jadi hepi family ya…karena senyummu adalah senyum kita, sedihmu adalah sedih kita bersama…aku sayang kalian semua

h1

Selamat Ulang Tahun Adekku

Desember 9, 2009

Puisi Ulang Tahun

Rentang waktu

terkadang membuat kita lupa

bahwa kita semakin dewasa

Rentang waktu

terkadang membuat kita lupa

bahwa kita telah melanggar titah Yang Kuasa

Rentang waktu

terkadang membuat kita sadar

bahwa kita hanya manusia

yang tak punya apa-apa

selain jasad yang tak berguna

Rentang waktu

terkadang membuat kita sadar

bahwa Tuhan tidak melihat harta dan rupa

melainkan hati yang ada di dalam dada

dan amal jasad yang lata

Walau Einstein berkata bahwa rentang waktu itu berbeda

tergantung dalam keadaan apa kita berada

Namun Tuhan telah berkata,

“Hanya Akulah yang tahu umur manusia”.

Sekular barat berkata,

“Waktu adalah dollar di dalam kantung”

Namun Hasan Al-Bana berkata,

“Waktu adalah pedang, potong atau terpotong”.

Waktu…..

Alam terus menari dalam simfoninya

Waktu…..

Umur manusia didikte olehnya

Waktu….. setiap detaknya

memakukan kita di persimpangan jalan

jalan Tuhan atau jalan setan

Rentang waktu…..

semoga tak melalaikan kita

tuk terus berjalan di jalan-Nya

h1

Belajar Matematika Mengasyikkan

Desember 9, 2009

pasti asyik

h1

Tips Belajar Statistik

Desember 8, 2009

Belajar SPSS

Ikuti

Get every new post delivered to your Inbox.