Membuat Calculator (Mesin Hitung) Sederhana dengan Visual Basic 6.0
Program computer yang sudah sering kita dengar
adalah membuat kalkulator (mesin hitung elektronik). Berikut adalah tutorial
untuk membuat aplikasi kalkulator sederhana dengan VB 6.0 :
Jalankan Aplikasi VB 6.0
Desain Form1 seperti berikut ini
Atur properti komponen form1 seperti dalam tabel dibawah ini :
No.
|
Kontrol
|
Properties
|
1.
|
Commandbutton1
|
Name : cmd_1
Caption : 1
|
2.
|
Commandbutton2
|
Name : cmd_2
Caption : 2
|
3.
|
Commandbutton3
|
Name : cmd_3
Caption : 3
|
4.
|
Commandbutton4
|
Name : cmd_4
Caption : 4
|
5.
|
Commandbutton5
|
Name : cmd_5
Caption : 5
|
6.
|
Commandbutton6
|
Name : cmd_6
Caption : 6
|
7.
|
Commandbutton7
|
Name : cmd_7
Caption : 7
|
8.
|
Commandbutton8
|
Name : cmd_8
Caption : 8
|
9.
|
Commandbutton9
|
Name : cmd_9
Caption : 9
|
10.
|
Commandbutton10
|
Name : cmd_0
Caption : 0
|
11.
|
Commandbutton11
|
Name : cmd_hasil
Caption : =
|
12.
|
Commandbutton12
|
Name : cmd_tambah
Caption : +
|
13.
|
Commandbutton13
|
Name : cmd_kurang
Caption : -
|
14.
|
Commandbutton14
|
Name : cmd_kali
Caption : x
|
15.
|
Commandbutton15
|
Name : cmd_bagi
Caption : /
|
16.
|
Textbox
|
Name : txtNumber
Text :
|
17.
|
Label 1
|
Name : Label1
Caption : Timoresse
Kalkulator
|
Masukan script kode program berikut ini :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
| Dim mfirst As Single Dim msecond As Single Dim manswer As Single Dim mbutton As Integer Private Sub cmd_0_Click() txtNumber = txtNumber + "0" End Sub Private Sub cmd_1_Click() txtNumber = txtNumber + "1" End Sub Private Sub cmd_2_Click() txtNumber = txtNumber + "2" End Sub Private Sub cmd_3_Click() txtNumber = txtNumber + "3" End Sub Private Sub cmd_4_Click() txtNumber = txtNumber + "4" End Sub Private Sub cmd_5_Click() txtNumber = txtNumber + "5" End Sub Private Sub cmd_6_Click() txtNumber = txtNumber + "6" End Sub Private Sub cmd_7_Click() txtNumber = txtNumber + "7" End Sub Private Sub cmd_8_Click() txtNumber = txtNumber + "8" End Sub Private Sub cmd_9_Click() txtNumber = txtNumber + "9" End Sub Private Sub cmd_bagi_Click() mbutton = 4 mfirst = Val(txtNumber) txtNumber = "" End Sub Private Sub cmd_hasil_Click() msecond = Val(txtNumber) Select Case mbutton Case Is = 1 manswer = mfirst + msecond Case Is = 2 manswer = mfirst - msecond Case Is = 3 manswer = mfirst * msecond Case Is = 4 manswer = mfirst / msecond End Select txtNumber = manswer End Sub Private Sub cmd_kali_Click() mbutton = 3 mfirst = Val(txtNumber) txtNumber = "" End Sub Private Sub cmd_kurang_Click() mbutton = 2 mfirst = Val(txtNumber) txtNumber = "" End Sub Private Sub cmd_tambah_Click() mbutton = 1 mfirst = Val(txtNumber) txtNumber = "" End Sub |
Terima Kasih,
Semoga bermanfaat,
youtube.com: YouTube | Vimeo
BalasHapusyoutube.com: YouTube youtube converter to mp3 | Vimeo.com. Vimeo.com: YouTube.com: YouTube.com : vimeo.com. Videos: 4470 views