evaluateAsNeeded ( )

Function stats

Average user rating
530
394
9999
Support
FileMaker 7.0 +
Date posted
13 July 2016
Version
1
Recursive function
No

Author Info
 jfletch

1 functions

Average Rating None

author_avatar



 

Function overview

Prototype

evaluateAsNeeded  ( value )


Parameters

value  Supplied contents of a number field


Description

Tags:  Number   Evaluate   Calc  

Evaluates formulas entered into number fields.

Examples

Sample input

Any FileMaker-valid number calculation


Sample output

Number result

 

Function code

//evaluateAsNeeded ( value )

/*
If provided value is not entirely a number, this function will
attempt to evaluate it as if it were a formula and return
the calculated number. Otherwise it will simply return the
value. It is meant to be used on a number field that could
allow user to enter a calculation and get the result right
in the field.

Jonathan Fletcher, 7/13/16
Fletcher Data Consulting, jonathan@fletcherdata.com
No rights reserved.
Anyone may use this in any way they see fit.
*/

Let ( [
    ~val = value ;
    ~valTxt = GetAsText ( value ) ;

    ~result = Case (
            Filter ( ~valTxt ; ".0123456789" ) ≠ ~valTxt ;
                Evaluate ( ~valTxt ) ;
                ~val
            )
] ;
    ~result
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/394

    Prototype: evaluateAsNeeded( value )
    Function Author: jfletch (http://www.fmfunctions.com/mid/530)
    Last updated: 13 July 2016
    Version: 1

*/
// ===================================

 

Comments

Fabrice
30 July 2016



Hi,
I don't think your test is good enough.
Currently you do: Filter ( ~valTxt ; ".0123456789" ) ≠ ~valTxt
but "." is used in a few countries only: https://en.wikipedia.org/wiki/Decimal_mark
and "-" seems to me a valid number character, as well as "e" sometimes.

I'd rather suggest this test: ~val = GetAsNumber ( ~val )
 Bug report

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (32)
Date  (28)
XML  (27)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Layout  (15)
Interface  (15)
Text  (14)
Variables  (13)
Filter  (12)
Layout Objects  (11)
Design  (10)
Array  (8)