buat form seperti gambar ini:
masukkan script berikut :
Dim nilai1, nilai2 As Double
Dim operator As String
Private Sub Form_Activate()
txtinput = "0"
End Sub
Private Sub cmd0_Click()
txtinput = Val(txtinput + "0")
End Sub
Private Sub cmd1_Click()
txtinput = Val(txtinput + "1")
End Sub
Private Sub cmd2_Click()
txtinput = Val(txtinput + "2")
End Sub
Private Sub cmd3_Click()
txtinput = Val(txtinput + "3")
End Sub
Private Sub cmd4_Click()
txtinput = Val(txtinput + "4")
End Sub
Private Sub cmd5_Click()
txtinput = Val(txtinput + "5")
End Sub
Private Sub cmd6_Click()
txtinput = Val(txtinput + "6")
End Sub
Private Sub cmd7_Click()
txtinput = Val(txtinput + "7")
End Sub
Private Sub cmd8_Click()
txtinput = Val(txtinput + "8")
End Sub
Private Sub cmd9_Click()
txtinput = Val(txtinput + "9")
End Sub
Private Sub cmdbagi_Click()
nilai1 = Val(txtinput)
txtinput = ""
operator = "bagi"
End Sub
Private Sub cmdkali_Click()
nilai1 = Val(txtinput)
txtinput = ""
operator = "kali"
End sub
Private Sub cmdmin_Click()
nilai1 = Val(txtinput)
txtinput = ""
operator = "minus"
End Sub
Private Sub cmdplus_Click()
nilai1 = Val(txtinput)
txtinput = ""
operator = "plus"
End Sub
Private Sub cmdc_Click()
txtinput = 0
End Sub
Private Sub cmdpersen_Click()
txtinput = Val(txtinput) / 100
End Sub
Private Sub cmdplusmin_Click()
txtinput = Val(txtinput) * -1
End Sub
Private Sub cmdseperx_Click()
txtinput = 1 / Val(txtinput)
End Sub
Private Sub cmdsqrt_Click(Index As Integer)
txtinput = Sqr(txtinput)
End Sub
Private Sub cmdsamadng_Click()
nilai2 = Val(txtinput)
If operator = "minus" Then
txtinput = Val(nilai1 - nilai2)
ElseIf operator = "plus" Then
txtinput = Val(nilai1 + nilai2)
ElseIf operator = "bagi" Then
txtinput = Val(nilai1 / nilai2)
ElseIf operator = "kali" Then
txtinput = Val(nilai1 * nilai2)
End If
End Sub
Private Sub Command1_Click()
End
End Sub
jalankan dengan menekan f5, inilah gambarnya :
Tidak ada komentar:
Posting Komentar