• After more than 30 years running websites and forums I am retiring.

    I have made many friends through the years. I will cherish my time getting to know you. I wish you all the best. This was not an easy decision to make. The cost to keep the communities running has gotten to the point where it's just too expensive. Security certificates, hosting cost, software renewals and everything else has increased threefold. While costs are up ad revenue is down. It's no longer viable to keep things running.

    All sites will be turned off on Thursday 30 November 2023. If you are interested in acquiring any of the websites I own you can Email Schwarz Network.

J# Help needed

pano

Newcomer
Joined
Mar 29, 2004
Hi,
I'm pretty new to the J# environment. Would anyone know how to check if a numeric has been entered into a textbox?
I know in vb there's a command called IsNumeric. but there's nothing of the sort in J#.
Any help is welcome.
 

Nerseus

Danner
Joined
Oct 22, 2002
Location
Arizona, USA
Typically you have to write your own function for this. The function is normally written with a Try/Catch that attempts the conversion. If it converts, the function returns true. If it doesn't, it returns false.

Depending on the type of numeric you want to return true (whole numbers only, floats, "$" and "," chars), you'll have to pick the right conversion function.

-nerseus
 

pano

Newcomer
Joined
Mar 29, 2004
Nerseus said:
Typically you have to write your own function for this. The function is normally written with a Try/Catch that attempts the conversion. If it converts, the function returns true. If it doesn't, it returns false.

Depending on the type of numeric you want to return true (whole numbers only, floats, "$" and "," chars), you'll have to pick the right conversion function.

-nerseus
Thanks for the response. Any idea how you do this? like a small sample of some sort to get me going. Appreciate it if you could.

Cheers
 

Iceplug

Contributor
Joined
Aug 20, 2001
Location
California, USA
OK, I have a little demo here:
Code:
[COLOR=DarkSlateBlue]try[/COLOR]
{
  i = System.Int32.Parse(text, System.Globalization.NumberStyles.Currency);
[COLOR=DarkOrchid]  // Parse the text according to currency standards.
  // If it cannot be parsed, an exception is thrown.
  // Going to the catch block. [/COLOR] 
  MessageBox.Show("Conversion succeeded." + System.Convert.ToString(i));
} 
[COLOR=DarkSlateBlue]catch[/COLOR] (System.Exception ex) 
{
[COLOR=DarkOrchid]// If text cannot be parsed.[/COLOR]
  MessageBox.Show("Conversion failed.");
  MessageBox.Show(ex.ToString());
};
You can use your value type's .Parse method to convert the text into a number and specify currency formatting or whatever format you may want. Of course, text is the text that you have gotten from the textbox, and I used an Integer... you can use floating point numbers as well.
 

pano

Newcomer
Joined
Mar 29, 2004
buddy you saved me a lot of headache. Really appreciate the help. it works like a charm... :)
thanks a lot
 
Top Bottom