Pada postingan kali ini saya akan membagikan tentang cara membuat program kalkulator menggunakan VB 6.0.
2. Setelah itu Desainlah Form seperti ini
3. Lalu masuk coding dengan cara klik 2 kali di form dan paste kode ini
Dim Angka(1 To 2) As Single
Dim Operator As String
Dim Operator As String
Private Sub CmdAngka_Click(Index As Integer)
Text1.Text = Text1.Text & CmdAngka(Index).Caption
End Sub
Private Sub CmdHapus_Click(Index As Integer)
Text1.Text = ""
End Sub
Private Sub CmdHitung_Click()
Dim Hasil As Single
If Text1.Text = "" Then Exit Sub
Angka(2) = CSng(Text1.Text)
Select Case Operator
Case "+"
Hasil = Angka(1) + Angka(2)
Case "-"
Hasil = Angka(1) - Angka(2)
Case "*"
Hasil = Angka(1) * Angka(2)
Case "/"
Hasil = Angka(1) / Angka(2)
End Select
Text1.Text = Hasil
End Sub
Private Sub CmdOperator_Click(Index As Integer)
If Text1.Text = "" Then Exit Sub
Angka(1) = CSng(Text1.Text)
Operator = CmdOperator(Index).Caption
Text1.Text = ""
End Sub
Text1.Text = Text1.Text & CmdAngka(Index).Caption
End Sub
Private Sub CmdHapus_Click(Index As Integer)
Text1.Text = ""
End Sub
Private Sub CmdHitung_Click()
Dim Hasil As Single
If Text1.Text = "" Then Exit Sub
Angka(2) = CSng(Text1.Text)
Select Case Operator
Case "+"
Hasil = Angka(1) + Angka(2)
Case "-"
Hasil = Angka(1) - Angka(2)
Case "*"
Hasil = Angka(1) * Angka(2)
Case "/"
Hasil = Angka(1) / Angka(2)
End Select
Text1.Text = Hasil
End Sub
Private Sub CmdOperator_Click(Index As Integer)
If Text1.Text = "" Then Exit Sub
Angka(1) = CSng(Text1.Text)
Operator = CmdOperator(Index).Caption
Text1.Text = ""
End Sub
No comments:
Post a Comment