Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • *Experts*
Posted

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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
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

  • Leaders
Posted

OK, I have a little demo here:

[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.

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...