Results 1 to 7 of 7

Thread: RESOLVED

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    2

    Question RESOLVED

    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!!!
    Attached Files Attached Files
    Last edited by airtas; Jun 14th, 2004 at 09:33 AM.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    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:
    1. Dim thiscolor As String
    2.         thiscolor = Lbllamp1.BackColor.Name
    3.         Select Case thiscolor
    4.             Case "Red"
    5.                 Lbllamp1.BackColor = System.Drawing.Color.Black
    6.                 Lbllamp2.BackColor = System.Drawing.Color.Green
    7.                 'after executed the above code lines, LblLamp1 will be BLACK !!! So I have to intercept also this case
    8.             Case "Black"
    9.                 If Lbllamp2.BackColor.Name = "Green" Then
    10.                     Lbllamp2.BackColor = System.Drawing.Color.Black
    11.                     Lbllamp3.BackColor = System.Drawing.Color.Yellow
    12.                 Else
    13.  
    14.                     Lbllamp3.BackColor = System.Drawing.Color.Black
    15.                     Lbllamp1.BackColor = System.Drawing.Color.Red
    16.                 End If
    17.         End Select
    18.  
    19.         'Static Luce As Byte = 0
    20.         'Select Case Luce
    21.         '    Case Is = 0
    22.         '        Lbllamp1.BackColor = System.Drawing.Color.Black
    23.         '        Lbllamp2.BackColor = System.Drawing.Color.Green
    24.         '    Case Is = 1
    25.         '        Lbllamp2.BackColor = System.Drawing.Color.Black
    26.         '        Lbllamp3.BackColor = System.Drawing.Color.Yellow
    27.         '    Case Is = 2
    28.         '        Lbllamp3.BackColor = System.Drawing.Color.Black
    29.         '        Lbllamp1.BackColor = System.Drawing.Color.Red
    30.         'End Select
    31.         'If Luce < 2 Then
    32.         '    Luce += 1
    33.         'Else
    34.         '    Luce = 0
    35.         'End If
    Live long and prosper (Mr. Spock)

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    2
    thats a lil 2 complex.... anyone else can help?

  4. #4
    Lively Member ayan's Avatar
    Join Date
    Jan 2004
    Posts
    112
    this?
    VB Code:
    1. Select Case Label1.BackColor.Name
    2.          Case "Red"
    3.             Label1.BackColor = Color.Black
    4.             Label2.BackColor = Color.Black
    5.             Label3.BackColor = Color.Green
    6.          Case "Black"
    7.             If Label3.BackColor.Name = "Green" Then
    8.                Label3.BackColor = Color.Black
    9.                Label2.BackColor = Color.Yellow
    10.             Else
    11.                Label2.BackColor = Color.Black
    12.                Label1.BackColor = Color.Red
    13.             End If
    14.       End Select

  5. #5
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    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!
    Live long and prosper (Mr. Spock)

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi airtas,

    Looks to me like ayan solved your problem. If so, you can mark your thread "Resolved" by editing your first post.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  7. #7
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    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.
    Live long and prosper (Mr. Spock)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width