473,320 Members | 1,820 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,320 software developers and data experts.

Alternative to Exceptions

Hello. I have an exception performance issue. What I am doing is trying to
cast a substring into an integer with CINT(string.substring(x,y)). And if it
doesn't work, I am catching the exception and then entering the substring
into a string variable. Here is my code.

Try
record9row.Item(y) = CInt(lineOfText.Substring(x, record9Sizes(y)))
Catch ex As Exception
record9row.Item(y) = lineOfText.Substring(x, record9Sizes(y))
End Try

The problem is I am looping through this over 500,000 times (populating a
database) and it takes a long time. Is there an alternative to exceptions
that could be used to check if the value in the substring can be cast into an
integer value? This is just taking too long.

Thanks in advance.

Matt

Sep 12 '06 #1
2 1143
See Int32.TryParse (2.0) or IsNumeric...

Generally exceptions should be for exceptional code i.e. the idea is to test
first that it would succeed rather than giving it a try and raising an
exception as part of the normal control flow (even if not using tryparse you
could have checked for example that the string contains nothing else than 0
to 9 characters)...

Also as a side note I don't really see the difference here (it seems like
you are populating the same column anyway ?)

--
Patrice

"Saubz" <sa***@newsgroups.nospama écrit dans le message de news:
65**********************************@microsoft.com...
Hello. I have an exception performance issue. What I am doing is trying
to
cast a substring into an integer with CINT(string.substring(x,y)). And if
it
doesn't work, I am catching the exception and then entering the substring
into a string variable. Here is my code.

Try
record9row.Item(y) = CInt(lineOfText.Substring(x, record9Sizes(y)))
Catch ex As Exception
record9row.Item(y) = lineOfText.Substring(x, record9Sizes(y))
End Try

The problem is I am looping through this over 500,000 times (populating a
database) and it takes a long time. Is there an alternative to exceptions
that could be used to check if the value in the substring can be cast into
an
integer value? This is just taking too long.

Thanks in advance.

Matt

Sep 12 '06 #2
Thanks for the response Patrice. TryParse and IsNumeric are the two things I
was looking for.

I'm not claiming to have exceptional code, either. It was just the only
thing I could come up with at the time (I am new to .NET and am not familiar
with all its features yet).

I am populating the same column, but I am entering the column into a
database from a flat file from a mainframe. The mainframe uses spaces rather
than zeros in some areas and VB chokes when I tell it to put spaces into an
Integer. But I'm sure your two method suggestions will work great.

Thanks!
-Matt

"Patrice" wrote:
See Int32.TryParse (2.0) or IsNumeric...

Generally exceptions should be for exceptional code i.e. the idea is to test
first that it would succeed rather than giving it a try and raising an
exception as part of the normal control flow (even if not using tryparse you
could have checked for example that the string contains nothing else than 0
to 9 characters)...

Also as a side note I don't really see the difference here (it seems like
you are populating the same column anyway ?)

--
Patrice

"Saubz" <sa***@newsgroups.nospama écrit dans le message de news:
65**********************************@microsoft.com...
Hello. I have an exception performance issue. What I am doing is trying
to
cast a substring into an integer with CINT(string.substring(x,y)). And if
it
doesn't work, I am catching the exception and then entering the substring
into a string variable. Here is my code.

Try
record9row.Item(y) = CInt(lineOfText.Substring(x, record9Sizes(y)))
Catch ex As Exception
record9row.Item(y) = lineOfText.Substring(x, record9Sizes(y))
End Try

The problem is I am looping through this over 500,000 times (populating a
database) and it takes a long time. Is there an alternative to exceptions
that could be used to check if the value in the substring can be cast into
an
integer value? This is just taking too long.

Thanks in advance.

Matt


Sep 13 '06 #3

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

Similar topics

16
by: David Turner | last post by:
Hi all I noticed something interesting while testing some RAII concepts ported from C++ in Python. I haven't managed to find any information about it on the web, hence this post. The problem...
0
by: Frank Rizzo | last post by:
Hello, I have a vb6 app that needs to access a bunch of business-layer .NET libraries. Initially, I wanted to Interop with the .NET libraries, but the downside is that all the .NET libraries...
4
by: tinman | last post by:
Hi.... There appears to be another way of checking if an object IsNothing in ..NET.....was wondering if this approach is better than the classic VB6 way of checking Is Nothing ? Example...
6
by: MARTIN LANNY | last post by:
Is there alternative to AxWebBrowser? I spent one whole week trying to make AxWebBrowser refresh php page. It never works. I tried over 10-15 suggestions from Microsoft itself. Refresh just...
11
by: Tantr Mantr | last post by:
I want to convert a string to a DateTime type. The user can enter the date in various formats and I am not sure if it will be a valid Date. Is it possible to check if a string can be converted to a...
5
by: Bry | last post by:
I've created a class that offers an enhanced way of handling fatal exceptions. The class allows the user to optionaly submit a http based anonymous error report to myself, and also records details...
30
by: pavan | last post by:
Is there a modern (OO, garbage collected etc...) programming language that can server as a good alternative for C for system programming. I wouldn't want to compromise too much on performance.
5
by: ajos | last post by:
hi frnds, im seperating html views, which is inside my servlets into a seperate jsp.the servlet contains certain exception methods that shows certain exceptions(if present)..the servlet...
0
RedSon
by: RedSon | last post by:
Chapter 3: What are the most common Exceptions and what do they mean? As we saw in the last chapter, there isn't only the standard Exception, but you also get special exceptions like...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.