473,625 Members | 3,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to check for numeric and enter in text box

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

Nov 20 '05 #1
20 41879
"anthonymelillo " <no************ @earthlink.net> 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

Nov 20 '05 #2
"anthonymelillo " <no************ @earthlink.net> scripsit:
Is there any way to check the entry in a text box and make sure it is
numeric ?
You can use 'Double.TryPars e' 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>
Nov 20 '05 #3
try the IdNumeric() function....
if IsNumeric then
do something cool
else
messageBox("So non-cool error")
end if

hope it helps
"Armin Zingler" <az*******@free net.de> wrote in message
news:el******** ******@tk2msftn gp13.phx.gbl...
"anthonymelillo " <no************ @earthlink.net> 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

Nov 20 '05 #4
"Stephen" <St*****@johnst ontrading.com> 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

Nov 20 '05 #5
Cor
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(textb ox1.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
Nov 20 '05 #6
"Cor" <no*@non.com> 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(textb ox1.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
Nov 20 '05 #7
"Cor" <no*@non.com> 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(textb ox1.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

Nov 20 '05 #8
Cor
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
Nov 20 '05 #9
"Armin Zingler" <az*******@free net.de> 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>
Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6310
by: Steve Wylie | last post by:
I am constructing an HTML questionnaire and one of the questions requires people to rate some choices from 1 to 5, where 1 is their favourite and 5 is their least favourite: Car Bus Taxi cab Train Airplane
7
3926
by: BBFrost | last post by:
I'm receiving decimal values from database queries and placing them on a report page. The users want to see the following .... Db Value Display Value 123.3400 123.34 123.0000 123 i.e. I want to trim trailing zeros and (decimal point if no decimal values
2
3103
by: Kiran | last post by:
Hi, How can I check whether the value entered in a textbox is numeric without doing a postback Kiran
11
4534
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing opinion of how I want to handle the 'user experience' in the application I'm creating. While I know I could allow the user to enter in number and alpha text - in a text box - and then tell them when the execuate a command "This is not numeric data", I...
3
6680
by: Aaron Smith | last post by:
I found an quick and dirty example of a numeric text box that converts the string to a currency mask.. Here is the code: Public Class NumericMaskedTextBox Inherits System.Windows.Forms.TextBox Private Sub NumericMaskedTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress 'the key press is not in the string (of numerals) If InStr(1, "0123456789.", e.KeyChar,...
12
3402
by: patang | last post by:
I have written the following code which allows user to enter only numbers and only one decimal point. This works fine. However, I want that user shouldn't enter a third number after decimal point, for example user should not be allowed to enter 12557.234. User should only be allowed to enter two digits after decimal point. I know I can validate it in the validate event, however, I was wondering if some can modify the following code so...
4
3680
by: John Salerno | last post by:
My code is below. The main focus would be on the OnStart method. I want to make sure that a positive integer is entered in the input box. At first I tried an if/else clause, then switched to try/except. Neither is perfect yet, but I was wondering which I should try for in the first place. I figure I need to check for an emptry string, non-numeric strings (maybe these are the same check), 0 and negative numbers (which might also fall into...
2
2138
by: Earl G via AccessMonster.com | last post by:
I have tried. But now I ask. I cannot get a control to accept a numeric entry (e.g. 0.23) without first entering a zero. I want to allow only two decimal places. But I would like numbers less than 1 to be enter by pressing the decimal then one or two digits. This is a normal entry method in Excel and Foxpro, etc.. Any help would be appreciated. Thanks in advance. -- Message posted via AccessMonster.com
3
7077
by: beary | last post by:
Hi, I have a number of text boxes for the user to input either numbers, or letters. Sometimes, the entry must be numeric. So I was thinking of using an onblur thing to check whether the value of the input is numeric, and if not, show an alert box to the user. I assume I would need to use getelementbyid. And on this page, there might be up to 30 similar input text fields, all of which need to be checked when the focus is lost. But...
0
8256
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8694
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7184
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6118
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4193
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1500
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.