What are you learning about FileMaker or programming from the puzzles and from the discussions about each days' puzzles?
Put your thoughts here.
I am learning that it is often important to coerce the data type of variables.
I have had a few issues in scripts where I have extracted a "number" from a string (with say MiddleWords) and not bothered to make it a number using GetAsNumber ( $var ). This has caused issues when FileMaker thinks 55 > 100.
I was taught by wimdecorte to always GetAsNumber(). Even now I still use that all the time. even: $i = GetAsNumber($i) + 1 in loops.
I don't think I will ever be that pedantic about it.
If a variable is established with 0 or 1, then that is a number and will remain so as you increment it.
If a variable is established with "1", that that is text and may cause issues.
If a variable is established with an expression, it is important to understand (from the Help) what data type each function returns. For example, Get(SystemPlatform) explicitly returns a number; Get(ApplicationVersion) returns text.
All that being said, I would not mark anyone down for using GetAsNumber. Better safe than sorry.
It does help to be consistent, i've found. Everytime I'm working with number variables, I can be consistent with myself.
GetAsNumber($myvar) isn't that far off from $myvar. Especially since I use aText to type "gtn" to spell it out.
I'll admit, I've gotten 'lazy' and have neglected to type it all out a few times.
But, I do agree with you. I like binary rules (my years of being a teacher). That mindset doesn't do well in FileMaker world.
And then there is the old "FileMaker stores everything as text" debate. I don't take sides, & mostly cast/coerce called variables because I feel better about it.
CustomList() is a brillant function.
Looping using variable namespaces are helpful and fast. Actually creating records and setting fields to handle large scall one-off tasks is generally not worthwhile.
You can create a LOT of variable repetitions...one script had somewhere around 400,000 at one point with no performance issues.
GetAsNumber() is a necessary function.
This is a big one. Depending on exactly what I'm doing, just adding a "+ 0" onto something will also force it to be a number.
David Jondreau wrote:GetAsNumber() is a necessary function.
David Jondreau wrote:
davidhead wrote:… it is important to understand (from the Help) what data type each function returns. For example, Get(SystemPlatform) explicitly returns a number; Get(ApplicationVersion) returns text
… it is important to understand (from the Help) what data type each function returns. For example, Get(SystemPlatform) explicitly returns a number; Get(ApplicationVersion) returns text
Hmm! Just to add some confusion, it's interesting that there are some functions, according to FMHelp, that return a numeral, but as text—e.g. Get ( WindowZoomLevel ). Why is that, I wonder?
Decades worth of code that is mostly all still being supported.
Yes, interesting indeed.
That particular case is explained in one of the examples:
"Returns 200* in Windows when the current window’s zoom percentage is set to 200 and Enlarge window contents to improve readability is selected."
So the engineers have to return a text result rather than a pure number.
This sort of support for OS variations and for support of functions such as readability must make the engineers pull their hair out!
Retrieving data ...