473,734 Members | 2,824 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

ExitErrorRoutin e:
Exit Function
ErrorRoutine:
MsgBox "Not what I FREAKING want!",vbCritic al,"I'm So Screwed"
Resume ExitErrorRoutin e
Exit Function

Function myFunctionXYZ()
on Error goto ErrorRoutine

Dim myLoopCount as Integer

RetryThisBlaste dCode:

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

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

"Too Bad.",vbCritica l,"Failed after 10 attempts"

instead it returns the error:

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

I'm hoping somebody can help. Thanks.
lq

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

I need instead the following:

If myLoopCount < 11 Then
RESUME RetryThisBlaste dCode
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

ExitErrorRoutin e:
Exit Function
ErrorRoutine:
MsgBox "Not what I FREAKING want!",vbCritic al,"I'm So Screwed"
Resume ExitErrorRoutin e
Exit Function

Function myFunctionXYZ()
on Error goto ErrorRoutine

Dim myLoopCount as Integer

RetryThisBlaste dCode:

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

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

"Too Bad.",vbCritica l,"Failed after 10 attempts"

instead it returns the error:

"Not what I FREAKING want!",vbCritic al,"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
298
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 the second error the error is reported by the function that called myFunctionXYZ, Function DooDah. Example: Function DooDah() on Error goto ErrorRoutine
4
13009
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 value". Any idea as to what I'm doing wrong? I'm sure it's something simple. Thanks in advance! public class ForLoop
5
2191
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 details of a random image from an access database. I know this works because when I run the query in access, it picks a different image each time (or close enough). However, when I view the .aspx page that this code-behind is for, it always picks...
14
3479
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 public member with a return type that is derived from System.Exception? I understand the importance of having clean, concise code that follows widely-accepted patterns and practices, but in this case, I find it hard to blindly follow a standard...
7
1843
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? I consistently see 2 rows in qryOwnrsDueITSwMissingAddr opening with a dbl-clik. Yet ?dcount("","qryOwnrsDueITSwMissingAddr") returns 3 and
5
1464
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 vb6 document and convert it into a vb.net program. Once I did that, the routine "check_for_file" I yanked out & put into my service program. The program though - doesn't work like the existing VB6 one does.
22
4032
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 receive 5 bytes buffer , I call the BeginReceive and then wait on AsyncWaitHandle.WaitOne() but it is signald imidiatly , and the next call to EndReceive return zero bytes length , also the buffer is empty. here is the code: public static byte...
1
20070
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 C:\WINNT\system32\ntdll.dll EAX:17020000 EBX:16400000 ECX:0000037F EDX:00000020 ESI:04120000 EDI:16FA0AD8 CS:EIP:001B:77FCE005 SS:ESP:0023:0012F3AC EBP:0012F3E4 DS:0023 ES:0023
3
2266
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 me an keycodedll error. i am trying the things like building web set up adding merge modules. passing registration key from .Net Help menu, About.Net. but it still giving same error. can anyone tell me can it is sufficient to pass registration key...
0
8946
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
8777
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9452
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...
1
9237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9184
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
8187
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
6737
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
6033
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3262
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

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.