|
of_buttonclicked
|
|
Full name
|
pfc_u_calculator.of_buttonclicked
|
Access
|
protected
|
Extend of
|
integer
|
Return value
|
integer
|
Prototype
|
protected function integer of_buttonclicked(string)
|
Name
|
Datatype
|
ldbl_currvalue
|
double
|
ldbl_value
|
double
|
li_rc
|
Integer
|
protected function integer of_buttonclicked (string as_key);//////////////////////////////////////////////////////////////////////////////
//
// Function: of_ButtonClicked
//
// Access: Protected
//
// Arguments:
// as_key The button/key pressed.
//
// Returns: Integer
// 1 if it succeeds
// -1 if an error occurs.
// 0 if the key is disregarded.
//
// Description:
// Perform the calculator actions depending on the button/key pressed.
//
//////////////////////////////////////////////////////////////////////////////
//
// Revision History
//
// Version
// 6.0 Initial version
//
//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1996-1997 Sybase, Inc. and its subsidiaries. All rights reserved.
// Any distribution of the PowerBuilder Foundation Classes (PFC)
// source code by other than Sybase, Inc. and its subsidiaries is prohibited.
//
//////////////////////////////////////////////////////////////////////////////
double ldbl_value
double ldbl_currvalue
Integer li_rc
// Validate the keystroke.
as_key = Lower(as_key)
CHOOSE CASE as_key
CASE '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', &
'/', '*', '+', '-', '=', 'c', 'ce'
CASE ELSE
Return -1
END CHOOSE
// Get the current running total.
ldbl_value = idbl_value
// Get the current value.
ldbl_currvalue = Double(is_currvalue)
CHOOSE CASE as_key
CASE 'c'
// Clear the Current variables.
is_curroperator = EMPTY
is_currvalue = EMPTY
// Clear the Repeat variables.
is_repeatoperator = EMPTY
idbl_repeatvalue = 0
// Clear the Running value.
of_SetValue(0, True)
CASE 'ce'
// Clear the Current Value but not the Current Operator.
is_currvalue = EMPTY
// Clear the Repeat Value but not the Repeat Operator.
idbl_repeatvalue = 0
// Determine if this should also Clear the Running value.
If is_curroperator=EMPTY Then
// Clear the Running value.
of_SetValue(0, True)
Else
// Do not Clear the Running value, only updates the current value.
of_SetValueOnRequestor ('0')
End If
CASE '.'
If Pos(is_currvalue, '.')>0 Then
// Disregard all '.' after one has been entered.
Return 0
End If
is_currvalue += as_key
of_SetValueOnRequestor (is_currvalue)
CASE '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
is_currvalue += as_key
idbl_repeatvalue = Double (is_currvalue)
of_SetValueOnRequestor (is_currvalue)
CASE '/', '*', '+', '-', '='
// Determine if this operator simply replaces the previous operator.
If of_IsOperator(as_key) And of_IsOperator(is_prevkeystroke) Then
is_prevkeystroke = as_key
is_curroperator = as_key
Return 1
End If
// Conclude the previous operation.
If Len(is_currvalue) > 0 And Len(is_curroperator) > 0 Then
// Perform a new Math operation.
If of_PerformMath (ldbl_value, is_curroperator, ldbl_currvalue) < 0 Then
Return -1
End If
ElseIf Len(is_currvalue) > 0 And Len(is_curroperator) = 0 Then
// There is no Math operation, use the current value as the new value.
ldbl_value = ldbl_currvalue
ElseIf as_key = '=' And Len(is_repeatoperator)>0 Then
// Perform a Repeat Math operation.
If of_PerformMath (ldbl_value, is_repeatoperator, idbl_repeatvalue) < 0 Then
Return -1
End If
End If
// Keep track of the last repeat action.
If of_IsOperator(as_key) Then
// The last operator is the new Repeat operator.
is_repeatoperator = as_key
// Update the repeat value to the current running value.
idbl_repeatvalue = ldbl_value
End If
// Reset the Current variables.
is_curroperator = EMPTY
is_currvalue = EMPTY
If of_IsOperator(as_key) Then
is_curroperator = as_key
End If
// Set the new value.
of_SetValue (ldbl_value, True)
END CHOOSE
// Store the previous keystroke.
is_prevkeystroke = as_key
Return 1
end function