J# Help needed

pano

Newcomer
Joined
Mar 29, 2004
Messages
4
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.
 
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
 
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
 
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.
 
buddy you saved me a lot of headache. Really appreciate the help. it works like a charm... :)
thanks a lot
 
Back
Top