PC Review


Reply
Thread Tools Rate Thread

how to check for numeric and enter in text box

 
 
anthonymelillo
Guest
Posts: n/a
 
      3rd Oct 2003
Is there any way to check the entry in a text box and make sure it is
numeric ?

Also, can I catch the enter key and make it call a button click event ?

Sorry if this sounds stupid, but I am trying to come to grips with the
differences in .Net since all my prior programming was done in VB6

Thanks
--
Tony



 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      3rd Oct 2003
"anthonymelillo" <nospam-(E-Mail Removed)> schrieb
> Is there any way to check the entry in a text box and make sure it
> is numeric ?
>
> Also, can I catch the enter key and make it call a button click event
> ?


Have a look at the Defaultbutton property of the Form.

> Sorry if this sounds stupid, but I am trying to come to grips with
> the differences in .Net since all my prior programming was done in
> VB6


I prefer not to limit the user's input when typing. Try to convert the
Textbox' content to a numeric value using the (shared) Parse function of the
destination type. Catch occuring exceptions to find out if conversion was
successful.


--
Armin

 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      3rd Oct 2003
"anthonymelillo" <nospam-(E-Mail Removed)> scripsit:
> Is there any way to check the entry in a text box and make sure it is
> numeric ?


You can use 'Double.TryParse' or 'IsNumeric'.

> Also, can I catch the enter key and make it call a button click event ?


Create a button and assign it to the form's 'AcceptButton' property.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
Stephen
Guest
Posts: n/a
 
      4th Oct 2003
try the IdNumeric() function....
if IsNumeric then
do something cool
else
messageBox("So non-cool error")
end if

hope it helps
"Armin Zingler" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "anthonymelillo" <nospam-(E-Mail Removed)> schrieb
> > Is there any way to check the entry in a text box and make sure it
> > is numeric ?
> >
> > Also, can I catch the enter key and make it call a button click event
> > ?

>
> Have a look at the Defaultbutton property of the Form.
>
> > Sorry if this sounds stupid, but I am trying to come to grips with
> > the differences in .Net since all my prior programming was done in
> > VB6

>
> I prefer not to limit the user's input when typing. Try to convert the
> Textbox' content to a numeric value using the (shared) Parse function of

the
> destination type. Catch occuring exceptions to find out if conversion was
> successful.
>
>
> --
> Armin
>



 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      4th Oct 2003
"Stephen" <(E-Mail Removed)> schrieb
> try the IdNumeric() function....
> if IsNumeric then
> do something cool
> else
> messageBox("So non-cool error")
> end if


I think, IsNumeric does not accept exactly the same formats as the Parse
method of the types does. It also can not check if it is within the value
range of the destination data type.


--
Armin

 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      4th Oct 2003
Armin,
Seriously I d'not understand this answer, (I hope you are not talking about
dragged information to the textbox).

>I think, IsNumeric does not accept exactly the same formats as the Parse
>method of the types does. It also can not check if it is within the value
>range of the destination data type.


In a textbox is normaly only text, so what is wrong to ask in a button event
"if not isnumeric(textbox1.text)".
I am really curious (for a simple method, not the best maybe)?

And for the not simple method I am as well as intrested?
:-) just to say that is well ment.
Cor


 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      4th Oct 2003
"Cor" <(E-Mail Removed)> schrieb
> Armin,
> Seriously I d'not understand this answer, (I hope you are not talking
> about dragged information to the textbox).
>
> >I think, IsNumeric does not accept exactly the same formats as the
> > Parse method of the types does. It also can not check if it is
> > within the value
> >range of the destination data type.

>
> In a textbox is normaly only text, so what is wrong to ask in a
> button event "if not isnumeric(textbox1.text)".
> I am really curious (for a simple method, not the best maybe)?
>
> And for the not simple method I am as well as intrested?
> :-) just to say that is well ment.
> Cor


Dim i As Integer
Dim s As String = "1234567890.12"
If IsNumeric(s) Then
i = Integer.Parse(s)
End If

Means: Calling IsNumeric doesn't help to find out whether the string can be
converted. The only way to find it out is trying to convert it (or call
Double.TryParse as Herfried mentioned).

--
Armin


 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      4th Oct 2003
"Cor" <(E-Mail Removed)> schrieb
> Armin,
> Seriously I d'not understand this answer, (I hope you are not talking
> about dragged information to the textbox).
>
> >I think, IsNumeric does not accept exactly the same formats as the
> > Parse method of the types does. It also can not check if it is
> > within the value
> >range of the destination data type.

>
> In a textbox is normaly only text, so what is wrong to ask in a
> button event "if not isnumeric(textbox1.text)".
> I am really curious (for a simple method, not the best maybe)?
>
> And for the not simple method I am as well as intrested?
> :-) just to say that is well ment.
> Cor



....and what I was trying to say in my first post: ;-)
Usually you also need to convert the string to a numeric data type (not only
check if it is numeric). I am not 100% sure, but I think that IsNumeric does
not perform exactly the same check as the conversion function called later.
Therfore IsNumeric does not help here.


--
Armin



 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      4th Oct 2003
Armin,
I try it and what the culture does with it, I give you an anser then.
Take some time (I have no time for that, but when it is longer then 3 days
it is never :-)
But I am intrested so I think it will be tomorrow.

Thanks,
Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      4th Oct 2003
"Armin Zingler" <(E-Mail Removed)> scripsit:
>> try the IdNumeric() function....
>> if IsNumeric then
>> do something cool
>> else
>> messageBox("So non-cool error")
>> end if

>
> I think, IsNumeric does not accept exactly the same formats as the Parse
> method of the types does. It also can not check if it is within the value
> range of the destination data type.


This depends on the data type of the destination variable.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text feild check for pattern or if last 5 are numeric? Billp Microsoft Access VBA Modules 1 16th Oct 2009 01:27 AM
enter numeric value starting with zero Prasoon Microsoft Excel Misc 3 18th Sep 2009 07:46 AM
Enter numeric as text in Excel worksheet should not create error =?Utf-8?B?ZXZhbnNpZ2h0?= Microsoft Excel Misc 1 1st May 2006 06:00 PM
Numeric in Text to convert back to the form of Numeric for VLookup Purposes achilles Microsoft Excel Misc 4 6th Feb 2006 07:05 AM
What event fires when user uses Alt & numeric key pad to enter text into a textbox Rob Nicholson Microsoft ASP .NET 10 23rd Aug 2005 01:43 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:38 AM.