Only numbers in StingGadgets

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Only numbers in StingGadgets

Post 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?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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
Post Reply