Hello, me again. Converting Harbour code to XSharp.
What are you using to validate that a user has entered a number in a textbox? I’ve tried a few things but can’t get it right. I really don’t want to get into workarounds using Regex, checking each character in the string etc. etc. There must be some existing function that does the trick - but I sure can't find it.
My pProject’s References are:
XSharp.Core
XSharp.RT
1)The following code sample always results in “Not OK”
IsNumeric() checks if the type of the param passed is a numeric type (INT, FLOAT etc), so it will indeed always return FALSE, when you pass a STRING to it.
You can use Int32.TryParse() (for integer values only) and Double.TryParse() (for floating point values) instead of Val(), both of those return TRUE if the conversion fron string was successful:
In my searches I came across TryParse(), but didn't realize it will return success boolean and not just set the result variable (which will be 0 in the case of non numeric input). Perfect!
The "Picture" way does not work, because this is a member of the GUI classes of VO, not of WinForms. This is one area (data entry/validation), where VO offers far better tools than .Net (out of the box) in my opinion.
It does offer some other related neat features though, Roland, please have a look into the ErrorProvider winforms component, for providing a visual sign to the user of what he has entered wrong etc. Here's also a small sample:
Hi all,
unfortunately at the current state to support picture masks for Windows Forms or WPF you have to use some 3rd party library, and they are not compatible with the xBase picture masks.
But there should be Willie's RightSLE anywhere, ported to Windows Forms. Maybe we should take it and move it to X#.
Look at http://www.wmconsulting.com/rightSLE.htm
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Thanks again Chris; what I've done for now, is simply validate data entered in the submit-button-event and make a red error label visible next to any 'offending' entry. As I start to convert some of more complex programs that make up my entire package, I'll have to look for a more elegant solution such as employing the 'CausesValidation' property as you suggest.
Thank you Wolfgang; for now, I'm using a more primitive - yet functional - approach as you can see in my response to Chris. I tend to shy away from 3rd party products.
Hi Roland,
I agree with you to stay away from 3rd party products whenever possibble, but in this case (RightSLE) we are speaking about an open source implementation of a TextBox that was created by a well known member of the VO and Vulcan community several years ago.
This code is easy to understand, and for sure has no hidden functionalities.
You may also remove code you don't need from this library, like the calculatorSLE or the calendarSLE.
In the long run you will sometimes need to use also 3rd party code if you have the sources.
I have tried to build my WPF applications without 3rd party controls, but I had to admit that that would inhibit me to deliver what my customers requested, and therefore I had to buy a control library (SyncFusion in my case) because I needed an advanced datagrid and an advanced RTF control that can save and read also Word documents.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it