473,327 Members | 2,055 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,327 software developers and data experts.

Return to code section and loop before giving up on an error.

I'm trying to figure out why I can't loop through a function
(myFunctionXYZ) after an error. The problem is that I can loop from the
error once back into the code section of myFunctionXYZ, but on the
second error the error is reported by the function that called
myFunctionXYZ, Function DooDah.

Example:

Function DooDah()
on Error goto ErrorRoutine

'run some very sexy unrelated code here

call myFunctionXYZ

ExitErrorRoutine:
Exit Function
ErrorRoutine:
MsgBox "Not what I FREAKING want!",vbCritical,"I'm So Screwed"
Resume ExitErrorRoutine
Exit Function

Function myFunctionXYZ()
on Error goto ErrorRoutine

Dim myLoopCount as Integer

RetryThisBlastedCode:

myLoopCount = myLoopCount + 1
'''blah blah blah this code returns an error and I'm gonna _
try it 10 times before giving up.

ExitErrorRoutine:
Exit Function
ErrorRoutine:
If err.number = 123 then
If myLoopCount < 11 Then
GoTo RetryThisBlastedCode
Else
msgBox "Too Bad.",vbCritical,"Failed after 10 attempts"
End If
Else
msgBox "Some unknown Error.",vbCritical,"Lousy Code Writing"
End If
Resume ExitErrorRoutine
Exit Function
What happens is it gets back from the error to RetryThisBlastedCode
only one time, then instead of trying 10 times as I want and returning
the error:

"Too Bad.",vbCritical,"Failed after 10 attempts"

instead it returns the error:

"Not what I FREAKING want!",vbCritical,"I'm So Screwed"

I'm hoping somebody can help. Thanks.
lq

Nov 13 '05 #1
1 1719
I found the answer:

I need instead the following:

If myLoopCount < 11 Then
RESUME RetryThisBlastedCode
laurenq uantrell wrote:
I'm trying to figure out why I can't loop through a function
(myFunctionXYZ) after an error. The problem is that I can loop from the error once back into the code section of myFunctionXYZ, but on the
second error the error is reported by the function that called
myFunctionXYZ, Function DooDah.

Example:

Function DooDah()
on Error goto ErrorRoutine

'run some very sexy unrelated code here

call myFunctionXYZ

ExitErrorRoutine:
Exit Function
ErrorRoutine:
MsgBox "Not what I FREAKING want!",vbCritical,"I'm So Screwed"
Resume ExitErrorRoutine
Exit Function

Function myFunctionXYZ()
on Error goto ErrorRoutine

Dim myLoopCount as Integer

RetryThisBlastedCode:

myLoopCount = myLoopCount + 1
'''blah blah blah this code returns an error and I'm gonna _
try it 10 times before giving up.

ExitErrorRoutine:
Exit Function
ErrorRoutine:
If err.number = 123 then
If myLoopCount < 11 Then
GoTo RetryThisBlastedCode
Else
msgBox "Too Bad.",vbCritical,"Failed after 10 attempts"
End If
Else
msgBox "Some unknown Error.",vbCritical,"Lousy Code Writing"
End If
Resume ExitErrorRoutine
Exit Function
What happens is it gets back from the error to RetryThisBlastedCode
only one time, then instead of trying 10 times as I want and returning the error:

"Too Bad.",vbCritical,"Failed after 10 attempts"

instead it returns the error:

"Not what I FREAKING want!",vbCritical,"I'm So Screwed"

I'm hoping somebody can help. Thanks.
lq


Nov 13 '05 #2

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

Similar topics

0
by: laurenq uantrell | last post by:
I'm trying to figure out why I can't loop through a function (myFunctionXYZ) after an error. The problem is that I can loop from the error once back into the code section of myFunctionXYZ, but on...
4
by: OutdoorGuy | last post by:
Greetings, I am attempting to compile the code below, but I am receiving an error message when I do so. The error message is: "CSO161: 'Forloop.CalcAvg(int)': Not all code paths return a...
5
by: Haydnw | last post by:
Hi, I have the code below as code-behind for a page which displays two images. My problem is with the second bit of code, commented as " 'Portfolio image section". Basically, the SQL query gets...
14
by: dcassar | last post by:
I have had a lively discussion with some coworkers and decided to get some general feedback on an issue that I could find very little guidance on. Why is it considered bad practice to define a...
7
by: MLH | last post by:
?dcount("","qryOwnrsDueITSwMissingAddr") when run in the immediate window return a number greater than the number of rows that display when the saved query is run - opening in the database window?...
5
by: Blasting Cap | last post by:
I have a VB6 program that runs as an app, that I want to both convert it to vb.net, and run it as a service on the server. I have been able to create the service, and what I did was to open the...
22
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to...
1
by: Vasuki | last post by:
Hi My application crashes all of a sudden giving me the following error. Can anybody help please? Exception code: C0000005 ACCESS_VIOLATION Fault address: 77FCE005 03:00002005...
3
by: Santosh | last post by:
Hii , i am developing an web application using asp.net with in it reporting purpose i am using crystal reports. it is working on fine on local server. but when i deploy it on web server it gives...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
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)...
1
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.