Tentang

CARA MEMBUAT CALKULATOR DENGAN VISUAL BASIC 6.0

1. Buka Microsoft visual basic 6.0

2. Pada jendela new projek pilih STANDAR EXE

3. buat sebuah form beri nama kalkulatordi dalam form tambahkan beberapa objek (textbox,comandButton,label,timer)

4. dengan menggunakan tool-tool yang ada di samping rancang seperti ini

5. klik view -> code terus masukan script ini (tanpa tanda kutip)

“Option Explicit

Private operand1 As Double, operand2 As Double

Private operator As String, memoryVal As Double

Private clearDisplay As Boolean, appVer As String

Private Declare Function ShellAbout Lib "shell32.dll" Alias _

"ShellAboutA" (ByVal hwnd As Long, ByVal szApp As String, _

ByVal szOtherStuff As String, ByVal hIcon As Long) As Long

Private Sub divide_Click()

operand1 = Val(display.Caption)

operator = "/"

display.Caption = vbNullString

End Sub

Private Sub equalto_Click()

Dim result As Double

On Error GoTo eh:

operand2 = Val(display.Caption)

If operator = "+" Then result = operand1 + operand2

If operator = "-" Then result = operand1 - operand2

If operator = "*" Then result = operand1 * operand2

If operator = "/" And operand2 <> 0 Then result = operand1 / operand2

If operator = "^" Then result = operand1 ^ operand2

display.Caption = result

clearDisplay = True

Exit Sub

eh:

Call MsgBox(Err.Description, , Err.Source)

End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)

Select Case Chr$(KeyAscii)

Case Is = "0": Number_Click (0)

Case Is = "1": Number_Click (1)

Case Is = "2": Number_Click (2)

Case Is = "3": Number_Click (3)

Case Is = "4": Number_Click (4)

Case Is = "5": Number_Click (5)

Case Is = "6": Number_Click (6)

Case Is = "7": Number_Click (7)

Case Is = "8": Number_Click (8)

Case Is = "9": Number_Click (9)

Case Is = "+": plus_Click

Case Is = "-": minus_Click

Case Is = "*": multiply_Click

Case Is = "/": divide_Click

Case Is = ".":

Case Else

If KeyAscii = vbKeyReturn Then

equalto_Click

ElseIf KeyAscii = vbKeyEscape Then

'correctEntry_Click

ElseIf KeyAscii = vbKeyBack Then

'back_Click

End If

End Select

End Sub

Private Sub Timer1_Timer()

Label1.Caption = Format(Now, "Mmm dd,yyyy hh:mm:ss ampm")

End Sub

Private Sub minus_Click()

operand1 = Val(display.Caption)

operator = "-"

display.Caption = vbNullString

End Sub

Private Sub multiply_Click()

operand1 = Val(display.Caption)

operator = "*"

display.Caption = vbNullString

End Sub

Private Sub Number_Click(Index As Integer)

If clearDisplay Then

display.Caption = vbNullString

clearDisplay = False

End If

display.Caption = display.Caption + Number(Index).Caption

End Sub

Private Sub plus_Click()

operand1 = Val(display.Caption)

operator = "+"

display.Caption = vbNullString

End Sub

6. klik file->make kalkulator exe

7. selamat mencoba

No comments:

Post a Comment