Article Preview
Buy Now
FEATURE
Numbers Please!
Part 1 of creating a numbers-only field
Issue: 17.2 (March/April 2019)
Author: Markus Winter
Author Bio: Markus is a Molecular Biologist who taught himself REALbasic programming in 2003 to let the computer deal with some exceedingly tedious lab tasks. Some call it lazy, he thinks it smart. He still thinks of himself as an "advanced beginner" at best.
Article Description: iption>No description ava
Article Length (in bytes): 12,496
Starting Page Number: Nu
Article Number: 17203
Related Link(s): None
Excerpt of article text...
Two questions that keep coming up on the forum are "How do I restrict a numeric entry to a certain range?" and "How do I get a
TextField
to accept numbers only?"Now those may seem rather simple questions and hardly worth an article in
xDev —after all, aTextField
hasMask
andLimitText
properties, so restricting the input should be easy. But hold your horses: it's much more complicated than you think!Let's start with a very simple example: a
TextField
that only accepts values between 0 and 1000. Let's try####
as the mask and setLimitText
to4
. This works pretty well, except... it also accepts 0023 as an entry, and I deeply dislike leading zeroes.And what if you want to have a range from -1000 to +1000? There is no mask that can accommodate this. So even at this very simple level the
mask
property has shown that it is not up to the task (and no, using "9999" as mask makes no difference).Mask
also has several long-standing bugs, so it might be best to stay clear of it.No problem. Surely Xojo has functions for this that we can use, doesn't it? There is a
Val()
function that converts text to a number, aStr()
function that converts a number to text, and yes, anIsNumeric()
function! And the documentation explicitly states:
...End of Excerpt. Please purchase the magazine to read the full article.