Jump to content
Sign in to follow this  
ptrex

Parameter Function With Input Validation

Recommended Posts

In this function I have created some input validations.

MsgBox(262144,'Debug_Loan_Amortisation',_Loan_Amortisation(10000,3,24));### Debug MSGBOX
 
Func _Loan_Amortisation($A,$B,$C)
    Local $D, $E
    If BitAND(IsNumber($A),$A>0) And BitAND(IsNumber($B),$B>0,$B<=100) And BitAND(IsInt($C),$C>0) Then
        $E=$B/100;
        $D=$A*($E/12)/(1-1/(EXP($C*LOG(1+$E/12))))
            SetError(0)
            Return $D
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc;==>_Loan_Amortisation

As you can see the If BtAND( ... does the validation to check if it's a number, integer and some values must be <=100,etc.

I am wondering if this is the only way to do it ?

I would like to see some alternatives if possible.

Thanks


Share this post


Link to post
Share on other sites

@Valuater

Thanks for the feedback and noticing the typo !!

the " 1-1 " can also be presented as, this reads better but has more brackets to plough throught.

$D=$A*($E/12)/(1-(1/EXP($C*LOG(1+$E/12))))

Both giving the same result


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...