Solved

Not returning from a function

Posted on 1998-12-29
6
165 Views
Last Modified: 2010-05-03
This may be a silly question. I want to call a function and, depending on the result, NOT return to the originating sub routine (if an error occurs for example). Can this be done? Have I missed something really obvious?

Thank you for any help you can give.

Peter
0
Comment
Question by:eccles
  • 2
  • 2
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
mukvij earned 200 total points
ID: 1452923
Yes This can be done but this is not a good programming practice. Depending on the condition you can branch to some other subroutine from the function . From there to another one and so on. You may choose to end your application from one of these subroutines. But the origional procedure is still in calling chain. Control returns to that procedure unless you choose to end the application from other brach in calling chain.
0
 

Author Comment

by:eccles
ID: 1452924
I understand. So control will ultimately return to the originating function/sub unless I terminate the application. Is this final? Is there no way around this? I really don’t want to have branch off indefinitely in the application.

Pete


0
 
LVL 12

Expert Comment

by:mark2150
ID: 1452925
Don't do this. You're going to wind up with an app that generates GPF's. You have to return from a function in order to clean up the internal stack. If you don't, your app will corrupt memory and eventually choke. Are you trying to write *buggy code*?

Allow the function to return and return a flag value so you know if you should trigger your error exit. If your code is not structured to handle this, then REWRITE it. It may be a PITA for *YOU* to rewrite, but it will be an even *BIGGER* PITA for the users when your app goes belly up and dumps their data.

If you don't *care* about the users then turn in your "I'm a programmer" card and go into a different trade. :-(

M

0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Expert Comment

by:mukvij
ID: 1452926
I totally agree with mark. As I said earlier branching off indefinitely is not a good programming practise as it does not confirm to standards of structured programming. I also agree with the idea given by Mark to have function return some flag based on which you can decide what to de next.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1452927
Yeah, it's code like that which has given BASIC it's bad rep among programming languages.

If you were to write something like that in *MY* shop you'ld be looking for a new job.

M

0
 

Author Comment

by:eccles
ID: 1452928
Thank you mukvij for your comments and help. Mark, please get off your high horse! It was a QUESTION for gods sake!!! For your information I have already written the code with each function returning a status code. I asked the question to see if there was a better way of doing it. I do not pretend to know everything about programming (unlike your self).

Once again mukvij thank you for your help.

Pete

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question