Ecere SDK/eC Forums http://ecere.com/forums/ Print view |
|
Numeric check http://ecere.com/forums/viewtopic.php?f=1&t=414 |
Page 1 of 1 |
Author: | shakeshuck [ Wed Dec 16, 2015 9:21 am ] |
Post subject: | Numeric check |
Hi again, Is there an isNumeric for strings or something similar? FloatFromString needs some input vetting before it's used. I can do it by hand, but just thought I'd ask as I would've thought a lot of folk would use it? If I'm the first then of course I could be wrong... |
Author: | jerome [ Wed Dec 16, 2015 9:57 am ] |
Post subject: | Re: Numeric check |
Hi shakeshuck, There are some options here. eC being a C super-set, anything C will work (e.g. strtod(), strtol()). The current eC way is probably calling OnGetDataFromString() on your numeric type: Code: Select all
Use strtol() or strtod() for finer control, which returns a pointer saying where the parsing ended. You may also want to look into using a SavingDataBox with a data type set to float or double, which will automatically convert to numbers and reject invalid input. Regards, -Jerome |
Author: | shakeshuck [ Wed Dec 16, 2015 11:04 am ] |
Post subject: | Re: Numeric check |
The input fields are ListBoxes; I did initially try setting the data type, but then discovered alignment doesn't work if you do. (With reference to the other thread on number alignment, in this case I wanted the value centered). I'll take a look at these, thanks. |
Author: | jerome [ Wed Dec 16, 2015 1:34 pm ] |
Post subject: | Re: Numeric check |
If you set the data type to e.g. float for a ListBox field, the data will normally be displayed with the alignment you setup for that field. But only when editing that data, it will be left-aligned. This could be a work around for now, if you want the editing to be e.g. right-aligned as well. Code: Select all
Code: Select all
https://github.com/ecere/ecere-sdk/blob ... ox.ec#L132 Then this should work: Code: Select all
|
Author: | shakeshuck [ Wed Dec 16, 2015 4:16 pm ] |
Post subject: | Re: Numeric check |
That's what I thought, but it isn't doing that for me; with alignment set to center, centering (at display time) is not occurring if I change the dataType to int or float. Of course it's highly possible I've unset something somewhere else that's causing this to happen... |
Author: | jerome [ Thu Dec 17, 2015 12:03 am ] |
Post subject: | Re: Numeric check |
Please post some sample code to compare. If you follow my example above it should work. (But you will need the custom type and the libecere tweak to get the 'edited' data box to follow the alignment as well) |
Author: | shakeshuck [ Thu Dec 17, 2015 5:10 am ] |
Post subject: | Re: Numeric check |
Video sent, using same MakeActive sample as before... Cheers. |
Author: | jerome [ Fri Dec 18, 2015 1:41 am ] |
Post subject: | Re: Numeric check |
Hi shakeshuck, I see what you mean. What happens is that the data types have a 'default alignment', and setting the dataType property after the alignment will set it to that default alignment. If you change the code to set the alignment after the dataType it will work again. Regards, Jerome |
All times are UTC-05:00 | Page 1 of 1 |
Powered by phpBB® Forum Software © phpBB Limited |