Langkah pertama untuk membuat program kalkulator sederhana ini, anda harus mempersiapkan komponen-komponen yg dibutuhkan seperti pada gambar disamping. lalu samakan propertisnya sesuai dengan tabel dibawah.

Lalu copy listing program dibawah ini:
Dim a As Integer
Dim b As Integer
Dim c As Variant
Private Sub Cmd_6239_Click()
If Txt1_6239.Text = "" And Txt2_6239.Text = "" Then
MsgBox "Anda belum masukkan angka", vbOKOnly + vbInformation, "INFORMASI"
If vbYes Then Exit Sub
End If
If Txt1_6239.Text = "" Then
MsgBox "Anda belum masukkan angka pertama", vbOKOnly + vbInformation, "INFORMASI"
If vbYes Then Exit Sub
End If
If Txt2_6239.Text = "" Then
MsgBox "Anda belum masukkan angka kedua", vbOKOnly + vbInformation, "INFORMASI"
If vbYes Then Exit Sub
End If
If Cmb1_6239.Text = "Pilihan" Then
MsgBox "Anda belum menentukan pilihan", vbOKOnly + vbInformation, "INFORMASI"
If vbYes Then Exit Sub
End If
a = Txt1_6239
b = Txt2_6239
If Cmb1_6239.ListIndex = 0 Then
c = a * b
ElseIf Cmb1_6239.ListIndex = 1 Then
c = a / b
ElseIf Cmb1_6239.ListIndex = 2 Then
c = a + b
Else
c = a - b
End If
Txt3_6239 = c
End Sub
Private Sub Txt1_6239_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyBack Then Exit Sub
If KeyAscii <> 57 Then
KeyAscii = 0
MsgBox "Anda Tidak Boleh Masukkan Huruf", vbOKOnly + vbInformation, "INFORMASI"
End If
End Sub
Private Sub Txt2_6239_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyBack Then Exit Sub
If KeyAscii <> 57 Then
KeyAscii = 0
MsgBox "Anda Tidak Boleh Masukkan Huruf", vbOKOnly + vbInformation, "INFORMASI"
End If
End Sub
Berikut hasil akhir tampilan dari program kalkulator sederhana yg siap untuk digunakan.
Showing posts with label Visual Basic. Show all posts
Showing posts with label Visual Basic. Show all posts