im a begginer, looking for project help
uusing vb.net
i need to make a traffic light, where RED turns to green to yellows, then back to red...while haveing the other 2 buttons black....i got red to green working but not green to yellow
help!!!
Printable View
im a begginer, looking for project help
uusing vb.net
i need to make a traffic light, where RED turns to green to yellows, then back to red...while haveing the other 2 buttons black....i got red to green working but not green to yellow
help!!!
Dear Airtas, I corrected your code. You have to remember that you are testing the color of lbllamp1 and it becomes Black after the first time you click your button. Then I put very similar code, under yours corrected. It use a static variable. You can choose to use what you prefer.
Good job:)
VB Code:
Dim thiscolor As String thiscolor = Lbllamp1.BackColor.Name Select Case thiscolor Case "Red" Lbllamp1.BackColor = System.Drawing.Color.Black Lbllamp2.BackColor = System.Drawing.Color.Green 'after executed the above code lines, LblLamp1 will be BLACK !!! So I have to intercept also this case Case "Black" If Lbllamp2.BackColor.Name = "Green" Then Lbllamp2.BackColor = System.Drawing.Color.Black Lbllamp3.BackColor = System.Drawing.Color.Yellow Else Lbllamp3.BackColor = System.Drawing.Color.Black Lbllamp1.BackColor = System.Drawing.Color.Red End If End Select 'Static Luce As Byte = 0 'Select Case Luce ' Case Is = 0 ' Lbllamp1.BackColor = System.Drawing.Color.Black ' Lbllamp2.BackColor = System.Drawing.Color.Green ' Case Is = 1 ' Lbllamp2.BackColor = System.Drawing.Color.Black ' Lbllamp3.BackColor = System.Drawing.Color.Yellow ' Case Is = 2 ' Lbllamp3.BackColor = System.Drawing.Color.Black ' Lbllamp1.BackColor = System.Drawing.Color.Red 'End Select 'If Luce < 2 Then ' Luce += 1 'Else ' Luce = 0 'End If
thats a lil 2 complex.... anyone else can help?
this?
VB Code:
Select Case Label1.BackColor.Name Case "Red" Label1.BackColor = Color.Black Label2.BackColor = Color.Black Label3.BackColor = Color.Green Case "Black" If Label3.BackColor.Name = "Green" Then Label3.BackColor = Color.Black Label2.BackColor = Color.Yellow Else Label2.BackColor = Color.Black Label1.BackColor = Color.Red End If End Select
I'm afraid dear Airtas, perhaps I can try to explain something if you ask me (if my english is enough!), anyway the code is only a little different from your original posted!:sick:
Hi airtas,
Looks to me like ayan solved your problem. If so, you can mark your thread "Resolved" by editing your first post.
Anyway, airtas, as I said, my first version is the most similar I found to your original code, just to give you an easy indication. The second, I think is more useful. For a so simple problem it could not be so clear, but you can choose to make a lot of different combination of colors that not depend on the previous state of light. If something is not clear....I'm here.;) :wave: