Contoh Visual Basic





Langkah pertama:
·       Klik label pada toolbox
·       Lalu  kita buat 3 label


Langkah kedua:
·       Klik textbox pada toolbox
·       Kita buat 3 textbox


Langkah ketiga:
·       Klik combobox pada toolbox
·       Kita buat 1 textbox

 
Langkah ke ampat:
·       Klik command pada toolbox
·       Kita buat 2 command button
Pengaturan Objek
objek
properti
nilai
label
caption
Bilangan1
label
caption
Bilangan2
label
caption
Jenis perhitungan
label
caption
Hasil perhirungan
textbox
Text1
Text1
textbox
Text2
Text2
textbox
Text3
Text3
Combo box
text
text
Command button
caption
proses
Command button
caption
hapus


Private Sub Command1_Click()
If Combo1.Text = "+" Then
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
ElseIf Combo1.Text = "-" Then
Text3.Text = Val(Text1.Text) - Val(Text2.Text)
ElseIf Combo1.Text = "*" Then
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
Text3.Text = Val(Text1.Text) / Val(Text2.Text)
End If
End Sub

Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
MEMBUAT PERHITUNGAN GAJI


Dim nilai(1 To 2) As String
Dim angka(1 To 2) As String

Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    If Combo1.Text = "ya" Or Combo1.Text = "tidak" Then
    Command1.SetFocus
    Else
    Combo1.SetFocus
    End If
End If
End Sub

Private Sub Command1_Click()
If Text1.Text = "" Then
Text1.SetFocus
ElseIf Text2.Text = "" Then
Text2.SetFocus
ElseIf Combo1.Text = "" Then
Combo1.SetFocus
Else
If Text2 > 40 Then
nilai(1) = Val(Text2.Text) - Val(40)
nilai(2) = nilai(1) * Val(25000)
Text4.Text = nilai(2)
Else
Text4.Text = "0"
End If
If Combo1.Text = "tidak" Then
angka(1) = Val(Text1.Text) * Val(10)
angka(2) = angka(1) / Val(100)
Text3.Text = angka(2)
Else
Text3.Text = "0"
End If
End If
Text5.Text = Val(Text1.Text) + Val(Text3.Text) + Val(Text4.Text)
End Sub


Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Combo1.Text = ""
End Sub

Private Sub Command3_Click()
MsgBox " anda ingin keluar...?", vbInformation

End
End Sub

Private Sub Form_Load()
Combo1.AddItem "ya"
Combo1.AddItem "tidak"
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    If Text1.Text = "" Then
    Text1.SetFocus
    Else
    Text2.SetFocus
    End If
End If
If Not (KeyAscii >= Asc("0") & Chr(13) And KeyAscii <= Asc("9") & Chr(13) Or KeyAscii = 13 Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyDelete) Then
KeyAscii = 0
MsgBox "hanya angka saja..!!!", vbCritical, "Ooo tidak bisa..!!!"
End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    If Text2.Text = "" Then
    Text2.SetFocus
    Else
    Combo1.SetFocus
    End If
End If
If Not (KeyAscii >= Asc("0") & Chr(13) And KeyAscii <= Asc("9") & Chr(13) Or KeyAscii = 13 Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyDelete) Then
KeyAscii = 0
MsgBox "hanya angka saja..!!!", vbCritical, "Ooo tidak bisa..!!!"
End If
End Sub
 

0 komentar:

Posting Komentar

 

Letjen Kazuya © 2011 Design by Best Blogger Templates | Sponsored by HD Wallpapers