1. Text to Number

How does one convert a text sequence to a number in Euphoria?

In working with EX07.EXW in the Win32 examples, text entered by the user 
in the dialog box Sle1 is retrieved using the function getText(). I 
assume this returns a sequence of ASCII characters. If I want to confine 
the user's input to a numeric range from 0 to n, how do I do this? In 
BASIC we would use a = VAL(x$).

Thank you.

new topic     » topic index » view message » categorize

2. Re: Text to Number

Hi Chris,

----- Original Message -----
From: "Chris" <c319chris at aol.com>
To: "EUforum" <EUforum at topica.com>
Subject: Text to Number


>
> How does one convert a text sequence to a number in Euphoria?
>
> In working with EX07.EXW in the Win32 examples, text entered by the user
> in the dialog box Sle1 is retrieved using the function getText(). I
> assume this returns a sequence of ASCII characters. If I want to confine
> the user's input to a numeric range from 0 to n, how do I do this? In
> BASIC we would use a = VAL(x$).
>

You have at least two easy alternatives.

1) Instead of the getText()function, use the getNumber() function. This will
convert the user input into an atom for you. If the conversion fails, it
returns a zero. This option does NOT constrain the user to only entering
digits, but does ensure that an atom is always returned.

2) When creating the edit control, use the ES_NUMBER style to constrain the
user to digits (0 - 9) and then use the getNumber() function. Note that this
literally only allows the digits '0' to '9' to be entered. Not periods or
commas etc...

  eg.  myNumberField = create(EditText, "", myWin, x,y,w,h, ES_NUMBER)


For more sophisticated solutions, you will need to apply some
character-by-character processing in an onKeyPress[] handler.
--------
Derek.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu