Menggunakan select case

Heuheu.. VB6, sementara yang ini dulu deh. Kalau pake yang fungsi-fungsi built in, nanti ya kita otak-atik lagi vb na, dan cari beberapa referensi. Ada banyak cara yang bisa ditempuh, bisa dipilih salah satu disini. Intinya, kita ya harus ngerti dengan penggunaan SELECT CASE.

Private Sub cmbNumber_Click()
Select Case cmbNumber
Case 1
lblBulan.Caption = “Januari”
lblJmlHari.Caption = 31
Case 2
lblBulan.Caption = “Februari”
lblJmlHari.Caption = 28
Case 3
lblBulan.Caption = “Maret”
lblJmlHari.Caption = 31
Case 4
lblBulan.Caption = “April”
lblJmlHari.Caption = 30
Case 5
lblBulan.Caption = “Mei”
lblJmlHari.Caption = 31
Case 6
lblBulan.Caption = “Juni”
lblJmlHari.Caption = 30
Case 7
lblBulan.Caption = “Juli”
lblJmlHari.Caption = 31
Case 8
lblBulan.Caption = “Agustus”
lblJmlHari.Caption = 31
Case 9
lblBulan.Caption = “September”
lblJmlHari.Caption = 30
Case 10
lblBulan.Caption = “Oktober”
lblJmlHari.Caption = 31
Case 11
lblBulan.Caption = “Nopember”
lblJmlHari.Caption = 30
Case 12
lblBulan.Caption = “Desember”
lblJmlHari.Caption = 31
End Select
End Sub
Private Sub Form_Activate()
lblBulan.Caption = “Bulan”
lblJmlHari.Caption = “Hari”
For i = 1 To 12
cmbNumber.AddItem i
Next
End Sub

Metode kedua

Private Sub cmbNumber_Click()
Dim bulan As String
Dim hari As String
Select Case cmbNumber
Case 1
bulan = MonthName(cmbNumber)
hari = 31
Case 2
bulan = MonthName(cmbNumber)
hari = 28
Case 3
bulan = MonthName(cmbNumber)
hari = 31
Case 4
bulan = MonthName(cmbNumber)
hari = 30
Case 5
bulan = MonthName(cmbNumber)
hari = 31
Case 6
bulan = MonthName(cmbNumber)
hari = 30
Case 7
bulan = MonthName(cmbNumber)
hari = 31
Case 8
bulan = MonthName(cmbNumber)
hari = 31
Case 9
bulan = MonthName(cmbNumber)
hari = 30
Case 10
bulan = MonthName(cmbNumber)
hari = 31
Case 11
bulan = MonthName(cmbNumber)
hari = 30
Case 12
bulan = MonthName(cmbNumber)
hari = 31
End Select
lblBulan.Caption = bulan
lblJmlHari.Caption = hari
End Sub
Private Sub Form_Activate()
lblBulan.Caption = “Bulan”
lblJmlHari.Caption = “Hari”
cmbNumber.Text = “Pilih”
For i = 1 To 12
cmbNumber.AddItem i
Next
End Sub

Metode ketiga

Private Sub cmbNumber_Click()
Dim bulan As String
Dim hari As String
Select Case cmbNumber
Case 1
bulan = “Januari”
hari = 31
Case 2
bulan = “Februari”
hari = 28
Case 3
bulan = “Maret”
hari = 31
Case 4
bulan = “April”
hari = 30
Case 5
bulan = “Mei”
hari = 31
Case 6
bulan = “Juni”
hari = 30
Case 7
bulan = “Juli”
hari = 31
Case 8
bulan = “Agustus”
hari = 31
Case 9
bulan = “September”
hari = 30
Case 10
bulan = “Oktober”
hari = 31
Case 11
bulan = “Nopember”
hari = 30
Case 12
bulan = “Desember”
hari = 31
End Select
lblBulan.Caption = bulan
lblJmlHari.Caption = hari
End Sub
Private Sub Form_Activate()
lblBulan.Caption = “Bulan”
lblJmlHari.Caption = “Hari”
cmbNumber.Text = “Pilih”
For i = 1 To 12
cmbNumber.AddItem i
Next
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s