Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Old October 15th 19, 08:42 AM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: May 2019
Posts: 63
Default Early exit from function?

Suppose I have the following function:

'------------------------------------
Function foo(x as Integer) as Integer

If (x < 1) Then
foo = 1 ' Exit point?
End If

MsgBox "I hope I don't get this far."

foo = 2
End foo
'-----------------------------------

Ideally, I'd like the function to exit as soon as I assign
a value to the function name. So, if x = 0, then I'd like
to immediately exit and have foo return 1.

Is there a way to have functions exit as soon as they are
assigned a value? Or do I need to hook up a bunch of
"Goto" statements that jump to the last line?

-Robert



  #2   Report Post  
Old October 15th 19, 09:56 AM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Sep 2016
Posts: 13
Default Early exit from function?

On 15/10/2019 08:42, RG III wrote:
Suppose I have the following function:

'------------------------------------
Function foo(x as Integer) as Integer

If (x < 1) Then
foo = 1 ' Exit point?


Exit Function

https://docs.microsoft.com/en-us/dot...exit-statement

--
Adrian C


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
15 minutes early Glenn_H Excel Discussion (Misc queries) 4 January 31st 08 07:44 PM
Exit Field vs Exit Button...... roy_ware Excel Programming 2 October 10th 07 04:05 PM
A Sub/Function to cause another Sub/Function to Exit IT_roofer Excel Programming 7 August 23rd 07 05:12 PM
End sub early if mismatch achidsey Excel Programming 2 November 9th 05 08:26 PM
If a called sub exit, how to the caller exit right away? luvgreen[_4_] Excel Programming 4 February 24th 04 06:06 PM


All times are GMT +1. The time now is 09:29 AM.

Powered by vBulletin® Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright 2004-2019 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"

 

Copyright © 2017