Posted by : G-Pikachu Senin, 21 November 2016

KODE PROGRM SEBAGAI BERIKUT:
Private Sub cmdOP_Click(Index As Integer)

On Error GoTo CheckIfOverFlowErr 

If bWasError Then
    Beep
    Exit Sub
End If

If bOp = True And bEqual = False Then 
 nOp = Index 'Remember the last operatore
 Exit Sub 'And..Exit sub
    ElseIf bEqual = True And bOp = True Then 
        If nOp = 1 Or nOp = 2 Then 
            nLastNum = 0 
                Else
                    nLastNum = 1 
        End If
End If

If nOp = 0 Then
    nResult = CDbl(lblOutput.Caption)
End If

Select Case nOp

    Case 1 '+
        nResult = nResult + nLastNum
    Case 2 '-
        nResult = nResult - nLastNum
    Case 3 '*
        nResult = nResult * nLastNum
    Case 4 '/
        
        If nLastNum = 0 Then
            lblOutput.Caption = "Cannot divide by zero."
            bWasError = True
            Exit Sub
            Else
                nResult = nResult / nLastNum
        End If
        
End Select

nOp = Index
bOp = True
bEqual = False
lblOutput.Caption = nResult

If Left$(lblOutput.Caption, 1) = "." Then
    lblOutput.Caption = "0" & nResult
End If

btnFocusEqual.SetFocus

Exit Sub
CheckIfOverFlowErr:

If Err.Number = 6 Then
    lblOutput.Caption = "Value is over max calculation limit."
    bWasError = True
End If

End Sub
 
 

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Belajar Bersama - Blogger Templates - Powered by Blogger - Designed by Johanes Djogan -