The document provides instructions for designing a calculator program in Visual Basic. It includes steps to design the user interface with buttons and displays for numbers, operators, and functions. It also provides the code to assign names and properties to the components and handle button click events to perform calculations and display results. The code samples show how to get input values, identify the selected operator, perform operations, and display or handle errors.
The document provides instructions for designing a calculator program in Visual Basic. It includes steps to design the user interface with buttons and displays for numbers, operators, and functions. It also provides the code to assign names and properties to the components and handle button click events to perform calculations and display results. The code samples show how to get input values, identify the selected operator, perform operations, and display or handle errors.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online from Scribd
The document provides instructions for designing a calculator program in Visual Basic. It includes steps to design the user interface with buttons and displays for numbers, operators, and functions. It also provides the code to assign names and properties to the components and handle button click events to perform calculations and display results. The code samples show how to get input values, identify the selected operator, perform operations, and display or handle errors.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online from Scribd
Frame1 Caption = spaces Frame2 Caption = spaces Text1 Name = tampilan Text = spaces Calender1 Name = Calender1 Command Name = angka Caption = 1 Index = 1 Command Name = angka Caption = 2 Index = 2 Command Name = angka Caption = 3 Index = 3 Command Name = angka Caption = 4 Index = 4 Command Name = angka Caption = 5 Index = 5 Command Name = angka Caption = 6 Index = 6 Command Name = angka Caption = 7 Index = 7 Command Name = angka Caption = 8 Index = 8 Command Name = angka Caption = 9 Index = 9 Command Name = tblhapus Caption = C Command Name = angka Caption = 0 Index = 0 Command Name = Desimal Caption = . Command Name = TAmbahkurang Caption = +/- Command Name = Tambah Caption = + Command Name = kali Caption = * Command Name = Satuper Caption = ½ Command Name = kurang Caption = - Command Name = bagi Caption = / Command Name = Samadengan Caption = =
3. Pada general ketik source program
Option Explicit Dim opr1 As Double, opr2 As Double Dim operator As String Dim hapustampilan As Boolean 4. Double click angka isi source program Private Sub angka_Click(Index As Integer) If hapustampilan Then tampilan.Text = "" hapustampilan = False End If tampilan.Text = tampilan.Text + Str(angka(Index).Index) End Sub
5. Double click bagi isi source program
Private Sub bagi_Click(Index As Integer) opr1 = Val(tampilan.Text) operator = "/" tampilan.Text = "" End Sub
6. Double click desimal (.) isi source program
Private Sub desimal_Click(Index As Integer) If hapustampilan Then tampilan.Text = "" hapustampilan = False End If If InStr(tampilan.Text, ".") Then Exit Sub Else tampilan.Text = tampilan.Text + "." End If End Sub
7. Double click kali isi source program
Private Sub kali_Click(Index As Integer) opr1 = Val(tampilan.Text) operator = "*" tampilan.Text = "" End Sub
8. Double click kurang isi source program
Private Sub kurang_Click(Index As Integer) opr1 = Val(tampilan.Text) operator = "-" tampilan.Text = "" End Sub
9. Double click samadengan source program
Private Sub samadengan_Click(Index As Integer) Dim x As Byte Dim hasil As Double On Error GoTo errorhandler opr2 = Val(tampilan.Text) If operator = "+" Then hasil = opr1 + opr2 If operator = "-" Then hasil = opr1 - opr2 If operator = "*" Then hasil = opr1 * opr2 If operator = "/" And opr2 <> "0" Then hasil = opr1 / opr2 tampilan.Text = Format(hasil, "###,###,###") hapustampilan = True Exit Sub errorhandler: x = MsgBox("Hitungan Salah", vbInformation & vbCrLf & Err.Description, "Pesan SAlah") tampilan.Text = "Salah" End Sub
10.Double click satuper isi source program
Private Sub satuper_Click(Index As Integer) If Val(tampilan.Text) <> 0 Then tampilan.Text = 1 / Val(tampilan.Text) End Sub
11.Double click tambah isi source program
Private Sub tambah_Click(Index As Integer) opr1 = Val(tampilan.Text) operator = "+" tampilan.Text = "" End Sub
12.Double click tamabahkurang isi source program
Private Sub tambahkurang_Click(Index As Integer) tampilan.Text = -Val(tampilan.Text) End Sub
13.Double click tblhapus isi source program
Private Sub tblhapus_Click(Index As Integer) tampilan.Text = "" End Sub