|
Don't implement it that way. Exceptions should be used only for exceptional circumstances, not part of normal code flow.
Rather than doing that, either us a MaskedTextBox (new in .NET 2.0) or use a regular expression to validate the input.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
When using Framework 2.0 you could use MaskedTextBox .
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Include the Visual Basic library and use the IsNumeric method.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
|
|
Greeeg wrote: a sorted list via a listbox control
|
|
|
|
|
Here is an easy way that doesn't rely on exceptions, regular expressions, or legacy VB libraries:
double numericValue;
bool isNumeric = double.TryParse(myTextBox.Text, out numericValue);
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Unfortunately there's no int.TryParse method to accompany that one.
|
|
|
|
|
|
Yes, there is an Int32.TryParse().
...or, at least I hope so, because I've used it...
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
dan neely wrote: Unfortunately there's no int.TryParse method to accompany that one.
Fortunately there are:
<br />
Int16.TryParse(string s,out short result)<br />
Int32.TryParse(string s, out int result)<br />
Int64.TryParse(string s,out long result)<br />
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
U can just use a simle java script for that.
Vipin
|
|
|
|
|
Vipin Venugopal wrote: U can just use a simle java script for that.
<input type=text name=txtPostalCode removed="if(!isNS4){if(event.keyCode > 45 || event.keyCode > 57) event.returnValue = false;}else{if(event.which < 45 || event.which > 57) returnfalse;}">
What?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Thnax for all the input peeps..I am going to try the Int32.TryParse..Btw, what is the best resource for knowing all in the classes and methods ( other than MSDN help )? I don't expect to know them all, but it would be good to have a good reference other than Google...
And Judah's reponse is for keytrokes that are between 0-9, correct?
Jude
|
|
|
|
|
Ahhh..I am using 2003...Int32.TryParse i not available for 1.1, and 2003 doe not support 2.0 from what I know, Corret?
Jude
|
|
|
|
|
Try this.
text box's KeyPress event
if ((int)e.KeyChar >= 48 & (int)e.KeyChar <= 57)
OR
in KeyDown or KeyUp event
if (e.KeyCode >= Keys.D0 & e.KeyCode <= Keys.D9)
this.Text = e.KeyValue.ToString();
Best of Luck.
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
hi
i want to print my datagrid records but it's more than one page . how to print it to multipage ?
|
|
|
|
|
Hi,
I have a question related to passing an array to a method.
In C++, if I have an array Arr[] with 20 elements, and I want to pass the array to a method, but starts from the 10th element, then I would do the following:
AMethod(Arr + 10);
If I want to do the same thing in C#, what would be the proper way? Thanks a lot.
|
|
|
|
|
Pass the offset and length. It is always a good practice.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Use the System.ArraySegment generic class.
|
|
|
|
|
Friends,
In Winforms, the control gets highlighted when it has an input focus either by pressing TAB key or by clicking it with mouse. Now what i want is that my button control should not get highlighted when it has an input focus. How can i do so ? Is there any property ?
Imtiaz
|
|
|
|
|
You can create such a button by setting the ControlStyles.Selectable value to false.
This is a sample of how to do it (#using directives omitted):
public class InertButton : Button
{
public InertButton()
{
SetStyle(ControlStyles.Selectable, false);
}
} That's it.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
i´m develop a local and remote application with sqlServer, the connection path where i´ve ip address, database, user and pass its on xml file, with two differents tags <local> and <remote>, and my question is, how its better, a class user with and attribute state , 0 local ,1 remote and when i use the class DataBase management if (i==0){read XML Local}else{read XML remote},or use a factory ?? and it i use a factory how can i do???
thanks for all
see you soon
|
|
|
|
|
I need to write some decimals on magnetic medium.
A C# decimal is realized in memory as series of 16 bytes.
How can I, without unsafe mode, code the conversion from deciamal into such an array byte[] and backwards?
HilSoft
|
|
|
|
|
If you use Reflector, you can see what the underlying implementation is for Decimal . For instance, there's an internal method called GetBytes that looks like this:
internal static void GetBytes(decimal d, byte[] buffer)
{
buffer[0] = (byte) d.lo;
buffer[1] = (byte) (d.lo >> 8);
buffer[2] = (byte) (d.lo >> 0x10);
buffer[3] = (byte) (d.lo >> 0x18);
buffer[4] = (byte) d.mid;
buffer[5] = (byte) (d.mid >> 8);
buffer[6] = (byte) (d.mid >> 0x10);
buffer[7] = (byte) (d.mid >> 0x18);
buffer[8] = (byte) d.hi;
buffer[9] = (byte) (d.hi >> 8);
buffer[10] = (byte) (d.hi >> 0x10);
buffer[11] = (byte) (d.hi >> 0x18);
buffer[12] = (byte) d.flags;
buffer[13] = (byte) (d.flags >> 8);
buffer[14] = (byte) (d.flags >> 0x10);
buffer[15] = (byte) (d.flags >> 0x18);
}
You could use reflection to call that internal method or you could use GetBits and convert the integers to bytes yourself. Here's what GetBits looks like:
public static int[] GetBits(decimal d)
{
return new int[] { d.lo, d.mid, d.hi, d.flags };
}
To convert the bits back into a Decimal , you can use the constructor that takes an int array. The array is in the same format that is output by GetBits .
Logifusion[^]
|
|
|
|