SEKOLAH TINGGI TEKNOLOGI 10 NOVEMBER

SEKOLAH TINGGI TEKNOLOGI 10 NOVEMBER
JL.RAYA BOGOR 01 JAKARTA TIMUR

Senin, 19 Oktober 2015

Membuat kalkulator Sederhana Menggunakan Aplikasi Visual Basic

A.   Memulai applikasi visual basic
1.      Klik start pilih visual basic 6

2.      Pilih mode  standard exe klik ok






2.
3.      Tambahkan beberapa control sehingga akan tampak sebagai berikut :

4.      Aturlah properties setiap control tersebeut sama seperti tabel berikut :
Control
Nama Control
Properties
Nilai Pengaturan
Form
StartUpPosition
2 – center Screen
Command1
caption
7
Command2
caption
8
Command3
caption
9
Command4
caption
4
Command5
caption
5
Command6
caption
6
Command7
caption
1
Command8
caption
2
Command9
caption
3
Command10
caption
Ce
Command11
caption
+
Command12
caption
-
Command13
caption
/
Command14
caption
*
Command15
caption
Keluar
Command16
caption
.
Command17
caption
0
Command18
caption
=

B. Memasukan koding
Double klik command1
Dim Op1, Op2 As Double
Dim Opr As String



Private Sub Command1_Click()
Text1.Text = Text1.Text + Command1.Caption
If cleardisplay Then
Text1.Text = "7"
cleardisplay = False
End If
End Sub
4.
Private Sub Command10_Click()
If InStr(Text1.Text, ".") Then
Exit Sub
Else
Text1.Text = Text1.Text + "."
End If
End Sub

Private Sub Command11_Click()
Text1.Text = Text1.Text + Command11.Caption
If cleardisplay Then
Text1.Text = "0"
cleardisplay = False
End If
End Sub

Private Sub Command12_Click()
Op2 = Val(Text1.Text)
Select Case Opr
Case "+": Text1.Text = Op1 + Op2
Case "*": Text1.Text = Op1 * Op2
Case "-": Text1.Text = Op1 - Op2
Case "/": Text1.Text = Op1 / Op2
End Select
End Sub


5.
Private Sub Command13_Click()
Op1 = Val(Text1.Text)
Opr = "+"
Text1.Text = ""
End Sub

Private Sub Command14_Click()
Op1 = Val(Text1.Text)
Opr = "-"
Text1.Text = ""
End Sub

Private Sub Command15_Click()
Op1 = Val(Text1.Text)
Opr = "*"
Text1.Text = ""
End Sub

Private Sub Command16_Click()
Op1 = Val(Text1.Text)
Opr = "/"
Text1.Text = ""
End Sub




6.
Private Sub Command17_Click()
Text1.Text = ""
End Sub

Private Sub Command18_Click()
End
End Sub

Private Sub Command2_Click()
Text1.Text = Text1.Text + Command2.Caption
If cleardisplay Then
Text1.Text = "8"
cleardisplay = False
End If
End Sub

Private Sub Command3_Click()
Text1.Text = Text1.Text + Command3.Caption
If cleardisplay Then
Text1.Text = "9"
cleardisplay = False
End If
End Sub




7.
Private Sub Command4_Click()
Text1.Text = Text1.Text + Command4.Caption
If cleardisplay Then
Text1.Text = "4"
cleardisplay = False
End If
End Sub

Private Sub Command5_Click()
Text1.Text = Text1.Text + Command5.Caption
If cleardisplay Then
Text1.Text = "5"
cleardisplay = False
End If
End Sub

Private Sub Command6_Click()
Text1.Text = Text1.Text + Command6.Caption
If cleardisplay Then
Text1.Text = "6"
cleardisplay = False
End If
End Sub




8.
Private Sub Command7_Click()
Text1.Text = Text1.Text + Command7.Caption
If cleardisplay Then
Text1.Text = "1"
cleardisplay = False
End If
End Sub

Private Sub Command8_Click()
Text1.Text = Text1.Text + Command8.Caption
If cleardisplay Then
Text1.Text = "2"
cleardisplay = False
End If
End Sub

Private Sub Command9_Click()
Text1.Text = Text1.Text + Command9.Caption
If cleardisplay Then
Text1.Text = "3"
cleardisplay = False
End If
End Sub

Private Sub Form_Load()
Text1.Text = ""
End Sub
9.

C.   Klik Run/start     maka kalkulator sudah dapat digunakan dengan baik.

0 komentar:

Posting Komentar

creatated by MUHAMMAD MAULANA. Diberdayakan oleh Blogger.

Ayo,,, Belajar

Ayo,,, Belajar