Minggu, 04 Desember 2011

Latihan 3 - Program Hotel - Visual Basic

Desain seperti di bawah ini :



Kemudian masukan script di bawah ni sesuai dengan procedurenya masing masing :

'Text1 -- > Nama Penyewa
'Combo1 --> Kode Kamar
'Text2 --> Jenis Kamar
'Option1-->Superior
'Option2 --> Deluxe
'Option3 --> Suite
'check1 --> internet
'check2 --> TV cable
'Text3 --> Biaya Sewa
'Text4 --> Fasilitas Tambahan
'Text5 --> Total Sewa
'Text6 --> Bayar
'Text7 --> Kembali


Private Sub Check1_Click()
If Check1.Value = 1 And Check2.Value = 1 Then
Text4.Text = "300000"
ElseIf Check1.Value = 0 And Check2.Value = 0 Then
Text4.Text = "0"
ElseIf Check1.Value = 1 And Check2.Value = 0 Then
Text4.Text = "200000"
ElseIf Check1.Value = 0 And Check2.Value = 1 Then
Text4.Text = "100000"
End If
End Sub

Private Sub Check2_Click()
If Check1.Value = 1 And Check2.Value = 1 Then
Text4.Text = "300000"
ElseIf Check1.Value = 0 And Check2.Value = 0 Then
Text4.Text = "0"
ElseIf Check1.Value = 1 And Check2.Value = 0 Then
Text4.Text = "200000"
ElseIf Check1.Value = 0 And Check2.Value = 1 Then
Text4.Text = "100000"
End If
End Sub

Private Sub Combo1_Click()
If Combo1.ListIndex = 0 Then
Text2.Text = "Single Bed"
Text3.Text = "0"
Option1.Value = False
Option2.Value = False
Option3.Value = False
ElseIf Combo1.ListIndex = 1 Then
Text2.Text = "Double Bed"
Text3.Text = "0"
Option1.Value = False
Option2.Value = False
Option3.Value = False
End If
End Sub

Private Sub Command1_Click()
Unload Me
End Sub

Private Sub Form_Load()
Combo1.AddItem "S001"
Combo1.AddItem "D001"

Text3.Text = "0"
Text4.Text = "0"
Text5.Text = "0"
Text6.Text = "0"
Text7.Text = "0"
End Sub

Private Sub Option1_Click()
If Option1.Value = True Then
    Text3.Text = "0"
    If Combo1.ListIndex = 0 Then
    Text3.Text = "1000000"
    ElseIf Combo1.ListIndex = 1 Then
    Text3.Text = "1200000"
    End If
ElseIf Option1.Value = False Then
    Text3.Text = "0"
End If
End Sub

Private Sub Option2_Click()
If Option2.Value = True Then
    Text3.Text = "0"
    If Combo1.ListIndex = 0 Then
    Text3.Text = "900000"
    ElseIf Combo1.ListIndex = 1 Then
    Text3.Text = "1000000"
    End If
ElseIf Option2.Value = False Then
    Text3.Text = "0"
End If
End Sub

Private Sub Option3_Click()
If Option3.Value = True Then
    Text3.Text = "0"
    If Combo1.ListIndex = 0 Then
    Text3.Text = "800000"
    ElseIf Combo1.ListIndex = 1 Then
    Text3.Text = "900000"
    End If
ElseIf Option3.Value = False Then
    Text3.Text = "0"
End If
End Sub

Private Sub Text3_Change()
Text5.Text = Val(Text4.Text) + Val(Text3.Text)
End Sub

Private Sub Text4_Change()
Text5.Text = Val(Text4.Text) + Val(Text3.Text)
End Sub

Private Sub Text6_Change()
Text7.Text = "0"
End Sub

Private Sub Text6_GotFocus()
If Text1.Text = "" Then
    MsgBox "Harap data diisi lengkap", , "Konfirmasi"
    Text1.SetFocus
ElseIf Combo1.ListIndex = -1 Then
    MsgBox "Harap pilih jenis kamar", , "Konfirmasi"
    Combo1.SetFocus
ElseIf Option1.Value = False And Option2.Value = False And Option3.Value = False Then
    MsgBox "Harap pilih type kamar", , "Konfirmasi"
    Option1.SetFocus
Else
    Text6.Text = ""
    Text6.SetFocus
End If
End Sub

Private Sub Text6_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text7.Text = Val(Text6.Text) - Val(Text5.Text)
End If
End Sub

1 komentar: