Solved

Not returning from a function

Posted on 1998-12-29
6
164 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pull multiple cvs files into one access table 28 68
How to debug this code 7 61
Macro Excel - Multiple If conditions 2 72
RUNRMTCMD from AS/400 12 47
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 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