Solved

Not returning from a function

Posted on 1998-12-29
6
162 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:mukvij
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now