Simplistic VB project

As title a very simple VB 6 project for those interested. These are the types of projects that you get to do at about GCSE level (UK) computing, and is a simple demonstration of the use of an Option Button.


Option Explicit

Private Sub optGreen_Click()
    If optGreen.Value = True Then
        lblTop.Caption = "Green is selected !"
        lblLeft.BackColor = RGB(0, 128, 64)
        lblRight.BackColor = RGB(0, 128, 64)
    End If
End Sub

Private Sub optRed_Click()
    If optRed.Value = True Then
        lblTop.Caption = "Red is selected !"
        lblLeft.BackColor = RGB(255, 0, 0)
        lblRight.BackColor = RGB(255, 0, 0)
    End If
End Sub

Private Sub optYellow_Click()
    If optYellow.Value = True Then
        lblTop.Caption = "Yellow is selected !"
        lblLeft.BackColor = RGB(255, 255, 0)
        lblRight.BackColor = RGB(255, 255, 0)
    End If
End Sub

Attached is the project file, now although this is fine there is another way to code this sort of project using an array of Option Buttons. Note the number of lines used for the code.
at GCSE using this gets a distinction :wink:

Option Explicit

Private Sub optColour_Click(Index As Integer)

Select Case Index
    Case 0
        lblTop.Caption = "Green is selected !"
        lblLeft.BackColor = RGB(0, 128, 64)
        lblRight.BackColor = RGB(0, 128, 64)
    Case 1
        lblTop.Caption = "Red is selected !"
        lblLeft.BackColor = RGB(255, 0, 0)
        lblRight.BackColor = RGB(255, 0, 0)
    Case 2
        lblTop.Caption = "Yellow is selected !"
        lblLeft.BackColor = RGB(255, 255, 0)
        lblRight.BackColor = RGB(255, 255, 0)
End Select

End Sub

Same form, just different control names. Now there are standard colours in vb so I could have used for example

lblLeft.BackColor = vbRed

but I prefer to use true RGB values as that gives a better range to use.

Any questions on above or comments, don’t hesitate.

DT.

Cheers DT. It shows my level of knowledge. I wouldn’t pass that’s for sure :cry:

Maybe DT we should have a sticky for samples done in different methods. Each programmer attacks coding in different ways for sure…Heck you could DIM the RGB items to a string also…and save a little typing…

Also I’m with you on vbRED also…hate the colors standard… like the RGB always!