Page 1 of 1

Only numbers in StingGadgets

Posted: Mon Jan 28, 2002 11:49 pm
by BackupUser
Code updated For 5.20+ (same As StringGadget() with Flag #PB_String_Numeric )

Restored from previous forum. Originally posted by Pupil.

I don't know if someone prior to me has posted something similar on this forum.
This is how you do if your string gadget only should accept numeric characters as input:

Code: Select all

#ES_NUMBER=$2000

ghandle.l=StringGadget(0,10,10,100,20,""); this should input numbers only
flag.l=GetWindowLong_(ghandle,#GWL_STYLE)
SetWindowLong_(ghandle,#GWL_STYLE,flag|#ES_NUMBER); now it should work as wanted

Note that you have to open a window prior to the above code.
Is there an easier way to accomplish the above?

Posted: Tue Jan 29, 2002 3:42 am
by BackupUser
Restored from previous forum. Originally posted by PB.

> Is there an easier way to accomplish the above?

Not really... even Visual Basic programmers have to write procedures to strip
out alpha characters from a numeric text box as they are typed.


PB - Registered PureBasic Coder

Posted: Tue Jan 29, 2002 10:21 pm
by BackupUser
Restored from previous forum. Originally posted by redacid.

Someone on this forum told me to do it this way (and it works):

number=StringGadget (45, 70,260, 51, 21,"")
SetWindowLong_(number, #GWL_STYLE, GetWindowLong_(number, #GWL_STYLE)|$2000)

regards,
Redacid
---
Only Amiga makes it possible!

Posted: Tue Jan 29, 2002 10:28 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
Someone on this forum told me to do it this way (and it works):

number=StringGadget (45, 70,260, 51, 21,"")
SetWindowLong_(number, #GWL_STYLE, GetWindowLong_(number, #GWL_STYLE)|$2000)
It works, but with two very major flaws:

(1) You can't type floats into it (eg: 3.14).
(2) You can still paste alpha text into it.

That's why I said that Visual Basic programmers had to write a procedure to
strip out alpha characters as they were typed (or pasted).

PB - Registered PureBasic Coder