Monday, April 23, 2012

contoh percabangan sederhana pada vb


Login Prompt dan Kondisi/percabangan pada visual basic.

Buatlah Form1 dan Form2 seperti di bawah ini.


#Form 1 

Private Sub Form_Load()
Label1.Caption = "LOGIN PROMPT"
Label2.Caption = "Username"
Label3.Caption = "Password"
Text1.Text = ""
Text2.Text = ""
Command1.Caption = "OK"
Command2.Caption = "Exit"

Label1.FontBold = True

Label1.Font = "Castellar"
Label2.Font = "Curlz MT"
Label3.Font = "Curlz MT"
Command1.Font = "Segoe Print"
Command2.Font = "Segoe Print"

Label1.FontSize = "14"
Label2.FontSize = "12"
Label3.FontSize = "12"

End Sub

#Command1 - Form1

Private Sub Command1_Click()

If (Text1.Text = "Admin") And (Text2.Text = "1ia26") Then
i = MsgBox("Login Anda berhasil", vbOKOnly + vbInformation, "Admin")
Form2.Show
Unload Me

Else:
i = MsgBox("Maap Login anda blum berhasil", vbOKOnly + vbCritical, "Admin")
End If

End Sub

#Command2 - Form1

Private Sub Command2_Click()
End
End Sub

############################################

#Form2

Private Sub Command1_Click()
Dim a As String
Dim b As String
Dim c As String
Dim d As Integer
Dim e As Integer
Dim f As String

a = Text2.Text
b = Text3.Text

If Text2.Text = "1" Then
a = "Ayam Bakar"
d = 10000
ElseIf Text2.Text = "2" Then
a = "Steak"
d = 20000
Else
MsgBox "Wrong Input", 3
End If
If Text3.Text = "1" Then
b = "Lemon Tea"
e = 3000
ElseIf Text3.Text = "2" Then
b = "Orange Juice"
e = 5000
Else
MsgBox "Wrong Input", 3
End If
f = Val(d) + Val(e)
c = a + " dan " + b + "Total = Rp. " + f
Text1.Text = c
End Sub

#Command 2 - Form2

Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""

End Sub

#Command 3 - Form2 

Private Sub Command3_Click()
End
End Sub

#Command4 -Form2 
(Tidak usah dibuat)

#Form 2

Private Sub Form_Load()
Label1.Caption = "1IA26's Menu"
Label2.Caption = "Food"
Label3.Caption = "Drink"
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""

Frame1.Caption = "Foods"
Label4.Caption = "1. Fried Chicken"
Label5.Caption = "2. Steak"

Frame2.Caption = "Your Choice"
Text1.Text = ""

Frame3.Caption = "Drinks"
Label6.Caption = "1. Orange Juice"
Label7.Caption = "2. Lemon Tea"

Command1.Caption = "Choice"
Command2.Caption = "Clean"
Command3.Caption = "Exit"
Command4.Caption = "Next Form"


End Sub

LP pertemuan ke tujuh

1. Apa yang kalian ketahui tentang sub menu pada vb?
2. Apa yang kalian ketahui tentang timer pada vb?
3. berikan contoh sederhananya

1 comment: