pano Posted March 30, 2004 Posted March 30, 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. Quote
*Experts* Nerseus Posted March 30, 2004 *Experts* Posted March 30, 2004 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 Quote "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
pano Posted March 30, 2004 Author Posted March 30, 2004 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 Quote
Leaders Iceplug Posted March 31, 2004 Leaders Posted March 31, 2004 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. Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
pano Posted March 31, 2004 Author Posted March 31, 2004 buddy you saved me a lot of headache. Really appreciate the help. it works like a charm... :) thanks a lot Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.