Selasa, 19 April 2011

Cara Membuat Kalkulator Sederhana dengan Visual Basic 6.0

  1. Buka Microsoft Visual Basic 6.0
  2. Pilih New Project, standard EXE
  3. Setelah muncul form1, tambahkan 1 buah textbox, dan  17 buah command
  4. Ganti Properti 
  • Form caption Kalkukator v1.0
  • Textbox1 caption dibiarkan kosong
  • Command1 caption 1
  • Command2 caption 2
  • Command3 caption 3
  • Command4 caption 4
  • Command5 caption 5
  • Command6 caption 6
  • Command7 caption 7
  • Command8 caption 8
  • Command9 caption 9
  • Command10 caption 0
  • Command11 caption +
  • Command12 caption -
  • Command13 caption *
  • Command14 caption /
  • Command15 caption =
  • Command16 caption Hapus
  • Command17 caption Keluar 
Desain Form seperti tampilan dibawah ini :


 


Setelah itu Klik kanan pada form, pilih view code dan ketik kode dibawah ini :


Listing Program:


Option Explicit
Dim a, b  As Double
Dim id, c As String

Private Sub Command1_Click()
Dim x As Integer
x = 1
c = Text1.Text

If Text1.Text = "" Then
Text1.Text = x
Else
        Text1.Text = c & x
 End If
End Sub

Private Sub Command2_Click()
Dim x As Integer
x = 2
c = Text1.Text


If Text1.Text = "" Then
Text1.Text = x
Else
        Text1.Text = c & x
 End If

End Sub

Private Sub Command3_Click()
Dim x As Integer
x = 3
c = Text1.Text

If Text1.Text = "" Then
Text1.Text = x
Else
        Text1.Text = c & x
 End If

End Sub

Private Sub Command4_Click()
Dim x As Integer
x = 4
c = Text1.Text

If Text1.Text = "" Then
Text1.Text = x
Else
        Text1.Text = c & x
 End If

End Sub

Private Sub Command5_Click()
Dim x As Integer
x = 5
c = Text1.Text

If Text1.Text = "" Then
Text1.Text = x
Else
        Text1.Text = c & x
 End If

End Sub

Private Sub Command6_Click()
Dim x As Integer
x = 6
c = Text1.Text

If Text1.Text = "" Then
Text1.Text = x
Else
        Text1.Text = c & x
 End If

End Sub

Private Sub Command7_Click()
Dim x As Integer
x = 7
c = Text1.Text

If Text1.Text = "" Then
Text1.Text = x
Else
        Text1.Text = c & x
 End If

End Sub

Private Sub Command8_Click()
Dim x As Integer
x = 8
c = Text1.Text


If Text1.Text = "" Then
Text1.Text = x
Else
        Text1.Text = c & x
 End If

End Sub



Private Sub Command9_Click()
Dim x As Integer
x = 9
c = Text1.Text


If Text1.Text = "" Then
Text1.Text = x
Else
        Text1.Text = c & x
 End If

End Sub

Private Sub Command10_Click()
Dim x As Integer
x = 0
c = Text1.Text


 If Text1.Text = "" Then
Text1.Text = x
Else
        Text1.Text = c & x
 End If

End Sub

Private Sub Command11_Click()
id = "+"
a = Val(Text1.Text)
Text1.Text = ""

End Sub

Private Sub Command12_Click()
id = "-"
a = Val(Text1.Text)
Text1.Text = ""

End Sub

Private Sub Command13_Click()
id = "*"
a = Val(Text1.Text)
Text1.Text = ""

End Sub

Private Sub Command14_Click()
id = "/"
a = Val(Text1.Text)
Text1.Text = ""
End Sub

Private Sub Command15_Click()

b = Val(Text1.Text)
If id = "+" Then
        Text1.Text = a + b

ElseIf id = "-" Then
        Text1.Text = a - b

ElseIf id = "*" Then
        Text1.Text = a * b

ElseIf id = "/" Then
        Text1.Text = a / b

End If
        id = "="
End Sub

Private Sub Command16_Click()
        Text1.Text = ""
End Sub

Private Sub Command17_Click()
        End
End Sub

Tidak ada komentar:

Posting Komentar