web stats

Sabtu, 09 Agustus 2014

Calculator (Semi-Intermediate) - Visual Basic

Program semi-intermediate ini adalah program kalkulator umum dengan tambahan operasi relasi dan operasi logika. Terlihat sederhana tetapi sangat bermanfaat dalam perhitungan matematis. Juga bisa digunakan saat bilangan dalam keadaan desimal. Tetapi ingat!! Gunakan titik saat memasukkan angkanya, bukan koma. Misalnya 0,34 - dalam program, Anda harus mengetik 0.34.
Buka program VB, kemudian buat project dengan tampilan dan properties seperti gambar.
Kemudian, ketikkan kode berikut dalam kode editor program tersebut.

Private Sub cmdplus_Click()
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
End Sub


Private Sub cmdminus_Click()
Text3.Text = Val(Text1.Text) - Val(Text2.Text)
End Sub


Private Sub cmdmulti_Click()
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
End Sub


Private Sub cmddiv_Click()
Text3.Text = Val(Text1.Text) / Val(Text2.Text)
End Sub


Private Sub cmdmod_Click()
Text3.Text = Val(Text1.Text) Mod Val(Text2.Text)
End Sub

Private Sub cmdequal_Click()
Text4.Text = Val(Text1.Text) = Val(Text2.Text)
End Sub

Private Sub cmdmore_Click()
Text4.Text = Val(Text1.Text) > Val(Text2.Text)
End Sub

Private Sub cmdless_Click()
Text4.Text = Val(Text1.Text) < Val(Text2.Text)
End Sub


Private Sub cmdmore_equal_Click()
Text4.Text = Val(Text1.Text) >= Val(Text2.Text)
End Sub


Private Sub cmdless_equal_Click()
Text4.Text = Val(Text1.Text) <= Val(Text2.Text)
End Sub

Private Sub cmdnot_equal_Click()
Text4.Text = Val(Text1.Text) <> Val(Text2.Text)
End Sub

Private Sub cmdclear_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub


Private Sub cmdexit_Click()
End
End Sub


Private Sub cmdand_Click()
If Text1.Text = "true" And Text2.Text = "true" Then
Text4 = "True"
ElseIf Text1.Text = "true" And Text2.Text = "false" Then
Text4 = "False"
ElseIf Text1.Text = "false" And Text2.Text = "true" Then
Text4 = "False"
Else
Text4 = "False"
End If
End Sub


Private Sub cmdor_Click()
If Text1.Text = "true" Or Text2.Text = "true" Then
Text4 = "True"
ElseIf Text1.Text = "true" Or Text2.Text = "false" Then
Text4 = "True"
ElseIf Text1.Text = "false" Or Text2.Text = "true" Then
Text4 = "True"
Else
Text4 = "False"
End If
End Sub


Setelah itu, klik tombol "Start" pada toolbar untuk mengaktifkan program sehingga muncul tampilan seperti berikut.
Tampilan program setelah mengetikkan angka 20,2 dan 19,9 dan mengklik tombol x (kali)
Tampilan program setelah memasukkan angka 100 di kedua sisi, dan mengklik tombol = (sama dengan)
 
Tampilan program setelah mengetikkan kata "true" dan "false" dan menekan tombol And

Program telah sukses dirancang!
Bila ada permasalahan, silahkan keluhannya di komentar!

Tidak ada komentar:

Posting Komentar