Membuat Kalkulator Sederhana dengan VB6

Iseng gak ada kerjaan, tiba-tiba kepikiran buat bikin suatu kalkulator sederhana, kali ini dari VB6. Oke langsung aja,

Pertama-tama siapkan objek-objeknya terlebih dahulu, yaitu :

  • Command1 – Command17 sebagai tombol kalkulator
  • Label1 – Label5 sebagai penampil output hasil

Lalu setkan semua command menjadi seperti berikut :

  • Command1.Caption = “1”
  • Command8.Caption = “2”
  • Command3.Caption = “3”
  • Command7.Caption = “4”
  • Command2.Caption = “5”
  • Command4.Caption = “6”
  • Command5.Caption = “7”
  • Command6.Caption = “8”
  • Command9.Caption = “9”
  • Command10.Caption = “+”
  • Command17.Caption = “0”
  • Command12.Caption = “x”
  • Command15.Caption = “mod”
  • Command11.Caption = “:”
  • Command13.Caption = “-“
  • Command14.Caption = “=”
  • Command16.Caption = “ULANGI”

Lalu setkan semua label menjadi seperti berikut

  • Label1.Caption = “”
  • Label2.Caption = “”
  • Label3.Caption = “”
  • Label4.Caption = “”
  • Label5.Caption = “=”

Susun semuanya hingga menjadi seperti berikut :

seluruhSetelah itu, ketiklah kode berikut :

Private Sub Command1_Click()
If Label2.Caption = "" Then
Label1.Caption = Label1.Caption + Command1.Caption
Else
Label4.Caption = Label4.Caption + Command1.Caption
End If
End Sub

Private Sub Command10_Click()
Label2.Caption = Command10.Caption
End Sub

Private Sub Command11_Click()
Label2.Caption = Command11.Caption
End Sub

Private Sub Command12_Click()
Label2.Caption = Command12.Caption
End Sub

Private Sub Command13_Click()
Label2.Caption = Command13.Caption
End Sub

Private Sub Command14_Click()
If Label2.Caption = "x" Then
Label3.Caption = Val(Label1.Caption) * Val(Label4.Caption)
ElseIf Label2.Caption = "+" Then
Label3.Caption = Val(Label1.Caption) + Val(Label4.Caption)
ElseIf Label2.Caption = "-" Then
Label3.Caption = Val(Label1.Caption) - Val(Label4.Caption)
ElseIf Label2.Caption = ":" Then
Label3.Caption = Val(Label1.Caption) / Val(Label4.Caption)
ElseIf Label2.Caption = "mod" Then
Label3.Caption = Val(Label1.Caption) Mod Val(Label4.Caption)
End If
End Sub

Private Sub Command15_Click()
Label2.Caption = Command15.Caption
End Sub

Private Sub Command16_Click()
Label1.Caption = ""
Label2.Caption = ""
Label3.Caption = ""
Label4.Caption = ""
End Sub

Private Sub Command17_Click()
If Label2.Caption = "" Then
Label1.Caption = Label1.Caption + Command17.Caption
Else
Label4.Caption = Label4.Caption + Command17.Caption
End If
End Sub

Private Sub Command2_Click()
If Label2.Caption = "" Then
Label1.Caption = Label1.Caption + Command2.Caption
Else
Label4.Caption = Label4.Caption + Command2.Caption
End If
End Sub

Private Sub Command3_Click()
If Label2.Caption = "" Then
Label1.Caption = Label1.Caption + Command3.Caption
Else
Label4.Caption = Label4.Caption + Command3.Caption
End If
End Sub

Private Sub Command4_Click()
If Label2.Caption = "" Then
Label1.Caption = Label1.Caption + Command4.Caption
Else
Label4.Caption = Label4.Caption + Command4.Caption
End If
End Sub

Private Sub Command5_Click()
If Label2.Caption = "" Then
Label1.Caption = Label1.Caption + Command5.Caption
Else
Label4.Caption = Label4.Caption + Command5.Caption
End If
End Sub

Private Sub Command6_Click()
If Label2.Caption = "" Then
Label1.Caption = Label1.Caption + Command6.Caption
Else
Label4.Caption = Label4.Caption + Command6.Caption
End If
End Sub

Private Sub Command7_Click()
If Label2.Caption = "" Then
Label1.Caption = Label1.Caption + Command7.Caption
Else
Label4.Caption = Label4.Caption + Command7.Caption
End If
End Sub

Private Sub Command8_Click()
If Label2.Caption = "" Then
Label1.Caption = Label1.Caption + Command8.Caption
Else
Label4.Caption = Label4.Caption + Command8.Caption
End If
End Sub

Private Sub Command9_Click()
If Label2.Caption = "" Then
Label1.Caption = Label1.Caption + Command9.Caption
Else
Label4.Caption = Label4.Caption + Command9.Caption
End If
End Sub

Setelah itu, coba dites

hasil

~~~

Sekian dari pembahasan super singkat ini, semoga bermanfaat🙂

2 thoughts on “Membuat Kalkulator Sederhana dengan VB6

Leave a Reply

Please log in using one of these methods to post your comment:

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