Membuat Kalkulator Sederhana Dengan VB 6.0
Untuk membuat aplikasi Visual Basic yang baru, lakukanlah langkah-langkah berikut ini :Langkah-langkah yang harus dilakukan adalah :
Jalankan Visual Basic.
Kotak dialog New Project akan muncul pada layar. Jika kotak dialog ini tidak muncul pada layar, pilihlah menu File >New Project, atau tekan tombol CTRL+N.
Pilih icon Standard EXE, lalu klik tombol OK.
Layar pengembangan Visual Basic akan muncul.
Bawa kursor ke Toolbox lalu pilihlah objek label,textbox,commandbutton lalu buatlah Form seperti berikut :
Pindahkan mouse ke jendela Properties yang terletak di sebelah kanan bawah layar Visual Basic. Pada daftar yang ada cari dan klik pada kata Caption lalu atur semua obyek seperti berikut
NAMA OBYEK
|
PROPERTI
|
SETTING
|
Form
|
Name
|
Latihan2
|
Caption
|
Kalkulator
Sederhana
|
|
Label1
|
Caption
|
Kalkulator
Sederhana
|
Fontsize
|
14
|
|
Label2
|
Caption
|
Nilai Pertama
|
Fontsize
|
12
|
|
Label3
|
Caption
|
Nilai Kedua
|
Fontsize
|
12
|
|
Label4
|
Caption
|
Hasil
|
Fontsize
|
12
|
|
Text1
|
Text
|
Dikosongkan
|
Name
|
Bil1
|
|
Text2
|
Text
|
Dikosongkan
|
Name
|
Bil2
|
|
Text3
|
Text
|
Dikosongkan
|
Name
|
Hasil
|
|
Command1
|
Caption
|
+
|
Fontsize
|
12
|
|
Command2
|
Caption
|
-
|
Fontsize
|
12
|
|
Command3
|
Caption
|
*
|
Fontsize
|
12
|
|
Command4
|
Caption
|
/
|
Fontsize
|
12
|
|
Command5
|
Caption
|
Selesai
|
Fontsize
|
12
|
Langkah berikutnya adalah menambahkan kode program pada Command Button yang telah Anda buat. Caranya, klik ganda objek Command Button tersebut hingga menampilkan jendela Code.
Listing Code :
Private Sub Command1_Click()
a = Val(Text1)
b = Val(Text2)
c = a + b
hasil = Str(c)
End Sub
Private Sub Command2_Click()
a = Val(Text1)
b = Val(Text2)
c = a - b
hasil = Str(c)
End Sub
Private Sub Command3_Click()
a = Val(Text1)
b = Val(Text2)
c = a * b
hasil = Str(c)
End Sub
Private Sub Command4_Click()
a = Val(Text1)
b = Val(Text2)
c = a / b
hasil = Str(c)
End Sub
Private Sub Command5_Click()
End
End Sub