Membuat kalkulator dengan VB

MEMBUAT KAKULATOR SEDERHANA

(DENGAN MENGGUNAKAN MENGUNAKAN VISUAL BASIK 6.0)

(Tugas wat minggu depan ne,,, <jo)

Start > Microsoft visual studio > visual Basic 6.0 > Ok > standart Exe

Yang pertama harus disiapkan adalah form yang bentuknya kayak gni ni,,,

Yakni form yang berisi 1 text box, dan 18 comandbutton (desain sesuai selera)

Keterangan:

KOMPONEN PROPERTY NILAI
Form1 CaptionBorder stile

Start position

Kalkulator3-fixed dialog

2-center screen

Text1 NameFont TextFont = Trebuchet MS

Font stile = Bold

Size = 14

Command1 Namecaption Cmd_11
Command2 Namecaption Cmd_22
Command3 NameCaption Cmd_33
Command4 NameCaption Cmd_44
Command5 NameCaption Cmd_55
Command6 NameCaption Cmd_66
Command7 NameCaption Cmd_77
Command8 NameCaption Cmd_88
Command9 NameCaption Cmd_99
Command10 NameCaption Cmd_00
Command11 NameCaption Cmd_kali*
Command12 NameCaption Cmd_bagi/
Command13 Namecaption Cmd_tambah+
Command14 NameCaption Cmd_kurang-
Command15 NameCaption Cmd_sama_dengan=
Command16 NameCaption Cmd_CC
Command17 NameCaption Cmd_offOFF

Kemudian double klik aja pada form lalu ketik project codenya  seperti ini nih,,,<<

Dim Nilai1, Nilai2, Hasil As Double

Dim Operator As String

Private Sub Cmd_0_Click()

If Text = “0″ Then

Text = “0″

Else

Text = Text & “0″

End If

End Sub

Private Sub Cmd_1_Click()

If Text = “0″ Then

Text = “1″

Else

Text = Text & “1″

End If

End Sub

Private Sub Cmd_2_Click()

If Text = “2″ Then

Text = “2″

Else

Text = Text & “2″

End If

End Sub

Private Sub Cmd_3_Click()

If Text = “3″ Then

Text = “3″

Else

Text = Text & “3″

End If

End Sub

Private Sub Cmd_4_Click()

If Text = “4″ Then

Text = “4″

Else

Text = Text & “4″

End If

End Sub

Private Sub Cmd_5_Click()

If Text = “5″ Then

Text = “5″

Else

Text = Text & “5″

End If

End Sub

Private Sub Cmd_6_Click()

If Text = “6″ Then

Text = “6″

Else

Text = Text & “6″

End If

End Sub

Private Sub Cmd_7_Click()

If Text = “7″ Then

Text = “7″

Else

Text = Text & “7″

End If

End Sub

Private Sub Cmd_8_Click()

If Text = “8″ Then

Text = “8?”

Else

Text = Text & “8″

End If

End Sub

Private Sub Cmd_9_Click()

If Text = “9″ Then

Text = “9?”

Else

Text = Text & “9″

End If

End Sub

Private Sub Cmd_bagi_Click()

If Nilai1 = 0 Then

Nilai1 = Val(Text)

Else

Nilai1 = Nilai1 / Val(Text)

End If

Operator = “/”

Text = “”

End Sub

Private Sub Cmd_c_Click()

Text = “”

Nilai1 = 0

Hasil = 0

Operator = “”

End Sub

Private Sub Cmd_kali_Click()

If Nilai1 = 0 Then

Nilai1 = Val(Text)

Else

Nilai1 = Nilai1 * Val(Text)

End If

Operator = “X”

Text = “”

End Sub

Private Sub Cmd_kurang_Click()

If Nilai1 = 0 Then

Nilai1 = Val(Text)

Else

Nilai1 = Nilai1 – Val(Text)

End If

Operator = “-”

Text = “”

End Sub

Private Sub Cmd_off_Click()

End

End Sub

Private Sub Cmd_sama_dengan_Click()

If Operator = “^” Then

Hasil = Nilai1 ^ Val(Text)

Text = Hasil

ElseIf Operator = “X” Then

Hasil = Nilai1 * Val(Text)

Text = Hasil

ElseIf Operator = “/” Then

Hasil = Nilai1 / Val(Text)

Text = Hasil

ElseIf Operator = “MOD” Then

Hasil = Nilai1 Mod Val(Text)

Text = Hasil

ElseIf Operator = “+” Then

Hasil = Nilai1 + Val(Text)

Text = Hasil

ElseIf Operator = “-” Then

Hasil = Nilai1 – Val(Text)

Text = Hasil

End If

Nilai1 = 0

Operator = “”

End Sub

Private Sub Cmd_tambah_Click()

If Nilai1 = 0 Then

Nilai1 = Val(Text)

Else

Nilai1 = Nilai1 + Val(Text)

End If

Operator = “+”

Text = “”

End Sub

Private Sub Cmd_titik_Click()

Text = Text & “.”

End Sub

Gimana Mudah khan,,

Okeyyy selamat mencobaa……

2 Comments

2 thoughts on “Membuat kalkulator dengan VB

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s