473,387 Members | 1,757 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.

Try Catch Statement help

I want to be able to accept a value in "goToTextBox.Text" if it is a decimal
value such as 3.4. My Try statement currently catches non-numeric or blank
data, which I want to retain. How can I accomplish this?

T.I.A.
Grant

Try
Dim goToInteger As Integer = Integer.Parse(goToTextBox.Text) - 1

If goToInteger < 0 Or goToInteger > countInteger Then
Statements........

Else
Statements........

End If
Catch theException As Exception
MessageBox.Show("Non numeric data or blank field.", "Selection
Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
With goToTextBox
.Focus()
.SelectAll()
End With
End Try
Nov 21 '05 #1
4 2697
See textbox.validating event

"Grant" <da*******@hotmail.com> wrote in message
news:2v*************@uni-berlin.de...
I want to be able to accept a value in "goToTextBox.Text" if it is a
decimal value such as 3.4. My Try statement currently catches non-numeric
or blank data, which I want to retain. How can I accomplish this?

T.I.A.
Grant

Try
Dim goToInteger As Integer = Integer.Parse(goToTextBox.Text) -
1

If goToInteger < 0 Or goToInteger > countInteger Then
Statements........

Else
Statements........

End If
Catch theException As Exception
MessageBox.Show("Non numeric data or blank field.", "Selection
Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
With goToTextBox
.Focus()
.SelectAll()
End With
End Try

Nov 21 '05 #2
Strictly speaking you shouldn't be trying to throw an exception here as there
is quite an overhead involved in raising exceptions...

I would use a boolean flag, something like:

Dim isGood As Boolean

isGood = False

If CInt(goToTextBox.Text) Then
isGood = True
Else
isGood = False
End If

If CDbl(goToTextBox.Text) Then
isGood = True
Else
isGood = False
End If

If Not isGood Then
MsgBox etc...
End If

HTH

"Grant" wrote:
I want to be able to accept a value in "goToTextBox.Text" if it is a decimal
value such as 3.4. My Try statement currently catches non-numeric or blank
data, which I want to retain. How can I accomplish this?

T.I.A.
Grant

Try
Dim goToInteger As Integer = Integer.Parse(goToTextBox.Text) - 1

If goToInteger < 0 Or goToInteger > countInteger Then
Statements........

Else
Statements........

End If
Catch theException As Exception
MessageBox.Show("Non numeric data or blank field.", "Selection
Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
With goToTextBox
.Focus()
.SelectAll()
End With
End Try

Nov 21 '05 #3
MN
Hi,
A suggestion :

If IsNumeric(goToTextBox.Text) Then
Statements........
Else
MessageBox.Show("Non numeric data or blank field.", "Selection Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
With goToTextBox
.Focus()
.SelectAll()
End With
End If

Hope this help; Regards.
"Grant" <da*******@hotmail.com> a écrit dans le message de news:
2v*************@uni-berlin.de...
I want to be able to accept a value in "goToTextBox.Text" if it is a
decimal value such as 3.4. My Try statement currently catches non-numeric
or blank data, which I want to retain. How can I accomplish this?

T.I.A.
Grant

Try
Dim goToInteger As Integer = Integer.Parse(goToTextBox.Text) -
1

If goToInteger < 0 Or goToInteger > countInteger Then
Statements........

Else
Statements........

End If
Catch theException As Exception
MessageBox.Show("Non numeric data or blank field.", "Selection
Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
With goToTextBox
.Focus()
.SelectAll()
End With
End Try

Nov 21 '05 #4
"MN at2 dot3 >" <1<n.m-recrut1ifrance2com3> schrieb:
A suggestion :

If IsNumeric(goToTextBox.Text) Then
Statements........


Notice that 'IsNumeric' will return 'True' for all valid numbers, but
doesn't take account if the number represented by the string can be stored
(parsed) in a certain numeric data type.

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

Nov 21 '05 #5

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

Similar topics

19
by: White Wolf | last post by:
Hi, I cannot believe my eyes, but so far I could not find out what is the name of the construct, which is built from one try block and the catch clauses (handlers). I am not looking for a...
7
by: Arjen | last post by:
Hi, I'm doing this: try { try { } catch(Exception ex){ throw;
23
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
13
by: Woody Splawn | last post by:
I have a try catch statement in a fucntion that is supposed to return a true or a false My code looks like this: Try mySqlConnection.Open() Dim Da1 As New SqlDataAdapter("Select JnlType,...
5
by: Patrick Dickey | last post by:
Hello, All! I'm modifying some source code that I downloaded from Planet-source-code a while back, and have a question about Try Catch statements. Basically, I'm wondering if I can do a Try with...
3
by: zacks | last post by:
The help isn't clear on this. If I have multiple catches and the first one catches the particular exception that was thrown, does it check the rest of the catches in the try/catch? For example,...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
3
by: =?Utf-8?B?SmVycnk=?= | last post by:
Hi All, I want to fill some textbox with properties from Active Directory. The fact is if the property is unavailable the program will crash. You can prevent this by using a try and catch. So...
8
by: =?Utf-8?B?U2F2dm91bGlkaXMgSW9yZGFuaXM=?= | last post by:
Is it right when placing the RETURN statement inside the TRY or inside the CATCH statement, when there is a FINALLY clause? Especially when there is a transaction going on, in the try/catch block?...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
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.