Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview

Buy Now

Issue 17.2 ('Barchart API')
Instant purchase and download via GumRoad!


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, a TextField has Mask and LimitText 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 set LimitText to 4. 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, a Str() function that converts a number to text, and yes, an IsNumeric() function! And the documentation explicitly states:

...End of Excerpt. Please purchase the magazine to read the full article.