473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How do i verify that an integer value has been entered into a textbox?

Hi all

I don't want to use the the Cint() or CDec() or other VB.Net Functions and
I dont want to restrict keystrokes in the textbox.

I am also using the "strict type semantic" settings that requires you to
explicitly state all conversions.
--
Yard Dancer
Practicing at home before I attempt to dance at the hall.
Apr 10 '07 #1
5 21251
You can try:

IsNumeric()
http://msdn2.microsoft.com/en-us/library/6cd3f6w1.aspx

Int32.TryParse
http://msdn2.microsoft.com/en-us/library/f02979c7.aspx

Hope that helps,

Chris

"YardDancer" <da*********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi all

I don't want to use the the Cint() or CDec() or other VB.Net Functions
and I dont want to restrict keystrokes in the textbox.

I am also using the "strict type semantic" settings that requires you to
explicitly state all conversions.
--
Yard Dancer
Practicing at home before I attempt to dance at the hall.

Apr 10 '07 #2
"YardDancer" <da*********@hotmail.comschrieb:
I don't want to use the the Cint() or CDec() or other VB.Net Functions
and I dont want to restrict keystrokes in the textbox.
\\\
Private Sub TextBox1_Validating( _
ByVal sender As Object, _
ByVal e As CancelEventArgs _
) Handles TextBox1.Validating
Dim SourceControl As TextBox = DirectCast(sender, TextBox)
Dim n As Integer
If Not Integer.TryParse(SourceControl.Text, n) Then
Me.ErrorProvider1.SetError( _
SourceControl, _
"Value must be an integer." _
)
Else
If Me.ErrorProvider1.GetError(SourceControl).Length 0 Then
Me.ErrorProvider1.SetError(SourceControl, "")
End If
...
End If
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Apr 10 '07 #3
I am using VS2003

Yes but i want to be more specific. after I have established that it is a
number then i want to find out what type of number floating point or integer

Convert.ToInt32(textbox.Text) throws Input string was not in a correct
format exception

Integer.Parse(textbox.text) Int32.Parse(textbox.text) both throw Input
string was not in a correct format exception
If Isnumeric (textbox.text) then
If CDec(textbox.text) <Cint(textbox.text) Then ' this works

Else
.......
End if
Else
....
End if

Remember i do not want to restrict keystrokes in the textbox

--
Yard Dancer
Practicing at home before I attempt to dance at the hall.
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:eN**************@TK2MSFTNGP02.phx.gbl...
"YardDancer" <da*********@hotmail.comschrieb:
>I don't want to use the the Cint() or CDec() or other VB.Net Functions
and I dont want to restrict keystrokes in the textbox.

\\\
Private Sub TextBox1_Validating( _
ByVal sender As Object, _
ByVal e As CancelEventArgs _
) Handles TextBox1.Validating
Dim SourceControl As TextBox = DirectCast(sender, TextBox)
Dim n As Integer
If Not Integer.TryParse(SourceControl.Text, n) Then
Me.ErrorProvider1.SetError( _
SourceControl, _
"Value must be an integer." _
)
Else
If Me.ErrorProvider1.GetError(SourceControl).Length 0 Then
Me.ErrorProvider1.SetError(SourceControl, "")
End If
...
End If
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Apr 10 '07 #4
Do you need to do this check for only one control, or do you need it
for several controls in your application?

I'm a big fan of inheriting a standard control and adding in my own
properties and methods.
In 2003 you create a usercontrol.
Edit the class and modify the Inherits UserControl to Inherits
TextBox. The UI goes away from the form, because you are now adding
functionality to the standard textbox instead of a user control.

Now you can create any properties, methods, and member variables that
you want to use in your application.

Public Function IsInteger() as boolean
your code to check for integer

Public Function IsDecimal() as boolean
your code to check for decimal

I like to use add on functionality that's similar to microsoft syntax.
Microsoft has a .ToString. I
add .ToInteger, .ToDecimal, .ToSingle, ...

Hope it helps.

Apr 10 '07 #5
Yard Dancer,

Why don't you build your own CInt or CDec Microsoft Net functions, probably
the latter is a better name than that used by you, because the namespace
where it is in starts with Microsoft and not with VisualBasic.
(Although AFAIK Mono has the same).

Cor

"YardDancer" <da*********@hotmail.comschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi all

I don't want to use the the Cint() or CDec() or other VB.Net Functions
and I dont want to restrict keystrokes in the textbox.

I am also using the "strict type semantic" settings that requires you to
explicitly state all conversions.
--
Yard Dancer
Practicing at home before I attempt to dance at the hall.

Apr 11 '07 #6

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

Similar topics

3
by: Chumley the Walrus | last post by:
I have a textbox control that represents a username in a password scheme, and I'm trying to turn the ID of the textbox control (the id = lgname ) into a session object. Doing lgname.text =...
4
by: ii2o | last post by:
Hi guys, I want to set the value of a textbox when someone hovers over an image (which is hyperlinked) but to no avail. Can anyone spot the problem here? I've wittled the code down to it's bare...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
1
by: Ted | last post by:
Here is a stored procedure I created in MySQL: CREATE PROCEDURE `sp_find_food`( IN search_string varchar(255) ) BEGIN DECLARE ss VARCHAR(257); SET ss = CONCAT('%',search_string,'%'); SELECT...
9
by: xian2 | last post by:
Hi All, I have been wroking on the databse for a while now and am on the stage of creating forms. I am trying to create a subform at the moment but am having some problems. I am using the...
1
by: silpa | last post by:
I have a form named dataentry1.aspx It has Name,Age,centimetres,metres textboxes. we will enter name in name textbox,age in age textbox. when we enter height in centimetres textbox, and after...
2
by: wildman | last post by:
I've coded a gridview that has used bound data to determine if I should show a button on a particular gridview row as follows: <asp:TemplateField> <ItemTemplate> <asp:Button ID="Submit"...
0
by: hemadribabu | last post by:
hi , i have a textbox in my asp.net page, in this textbox some integer value will be displayed , Now i have to make that displayed integer value to be displayed in INR format , plstell me how to...
4
beacon
by: beacon | last post by:
Hi everybody, I'm really hoping this will be the last problem I run into because I don't have much hair left to pull out! :) I have a form that the user will enter a census date (indexed field)...
1
by: mfaisalwarraich | last post by:
Hi everyboyd, im trying to make a function which will keep the cursor to its position if non integer value is entered into a textbox. im using the following code: Public Class Form1 Private...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.