Chikita leaderboard

Sabado, Nobyembre 12, 2011

How to use ComboBox in VB 6.0


Visual Basic 6.0 has more than enough Controls to use in every programming jobs and one of them is ComboBox. The ComboBox control is a sort of mixture between a ListBox and a TextBox control in that it also includes several properties and events that are more typical of the latter. ComboBox controls automatically sort their items using the Sorted property and you can add items at design time using the List item in the Properties window or using Additem property at Run time.
There's an interesting tip in this video tutorial and that is showing the years from 1900-2011 using Do-While Loop in ComboBox, a tedius task if you type it one by one from 1900-2011!Wow!

Here are the codes in this tutorial:

Dim a, b As Integer

Private Sub Combo1_Click()
If Combo1.Text = "Blue" Then
Label1.ForeColor = vbBlue
ElseIf Combo1.Text = "Red" Then
Label1.ForeColor = vbRed
ElseIf Combo1.Text = "Green" Then
Label1.ForeColor = vbGreen
End If
End Sub

Private Sub Command1_Click()
Label1.Caption = Combo2.Text + " " + Combo3.Text + ", " + Combo4.Text
End Sub

Private Sub Form_Load()
Combo1.AddItem "Blue"
Combo1.AddItem "Red"
Combo1.AddItem "Green"

Combo2.AddItem "January"
Combo2.AddItem "February"
Combo2.AddItem "March"
Combo2.AddItem "April"
Combo2.AddItem "May"
Combo2.AddItem "June"
Combo2.AddItem "July"
Combo2.AddItem "August"
Combo2.AddItem "September"
Combo2.AddItem "October"
Combo2.AddItem "November"
Combo2.AddItem "December"
a = 0
Do While a < 31
a = a + 1
Combo3.AddItem a
Loop

b = 1899
Do While b < 2011
b = b + 1
Combo4.AddItem b
Loop

End Sub

Share and Enjoy!

3 komento:

  1. thank you for post the simple program like this... i make sure i gonna be a best programmer....

    TumugonBurahin
  2. sir panu po dun sa case ng month ay february, di po ba hanggang 28 lang tapos pag leap year hanggang 29, panu po gawin sa code un, i try it with if condition, kaya lang to no avail sir, patulong naman po

    TumugonBurahin
  3. Ako po ay isang freshman sa mundo ng computer engineering at gusto kupo talaga ang programming ,dahil po sa kunting pag tuturo niu about prog. Mas naingganyo papo ako na matuto at someday maging programmer �� thanks sir!

    TumugonBurahin