Testing for a number?


R

Rob Meade

Hi all,

Ok, I'm used to VBScript with stuff like IsNumeric and the like...

How can I test a value is a numeric value in .net / win forms?

I have multiple text boxes and the user is able to enter numbers like thus:

1.01
5.50

and so on, I have some formatting going on to always return 2 decimal places
etc, but how can I test this is a number?

Also, when I set my variables when the button is clicked, should I take all
of the values as 'strings' to start with and then convert them (or try to) ,
or should I declare them as what I want them to be and then try to trap the
errors when they fail...ie, someone enters:

adfsd

in my nice number box....

Any info appreciated

Regards

Rob
 
Ad

Advertisements

T

Tim Wilson

You might consider authoring, or locating on the internet, a control that
restricts the key strokes to only numeric, and other appropriate number
formatting, keys.

Here is one example, although I'm not exactly sure how good it is because I
haven't had a need to use it.
http://www.codeproject.com/cs/miscctrl/numedit.asp

I'm sure if you google for others you will find more.
 
Ad

Advertisements

H

Herfried K. Wagner [MVP]

* "Rob Meade said:
Ok, I'm used to VBScript with stuff like IsNumeric and the like...

How can I test a value is a numeric value in .net / win forms?
Use 'Double.TryParse' to test/convert a string for/to a number.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Test post2 0
UI testing 0
Testing localized app? 3
Hit-testing a polygon? 2
How to test a dialog 3
Testing for Modal form 4
Testing for empty drives 1
Testing Internet connection? 1

Top