By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,191 Members | 1,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,191 IT Pros & Developers. It's quick & easy.

Recursive Function with Select Case fails to exit

P: n/a
When I loop through this function, it works fine until it hits End
Function - then it jumps to End Select. Very strange... This behavior
occurs when Case = 255. Any ideas why this is happening? Why doesn't the
function just end? Why the jump back in at End Select?

Thanks in advance.

Private Function GetRecurrenceType(r As Long, Optional s As Boolean) As
String
Dim strReturn As String
Select Case r
Case Is = 255
GetRecurrenceType =
GetRecurrenceType(Nz(DLookup("RecurrenceTypeDispla y", _
"tblAppointmentsRecurring"), 2), True)
Case Is = 1
If s Then strReturn = "frmRecurrencePatternWeely"
Case Is = 2
If s Then strReturn = "frmRecurrencePatternMonthly"
Case Is = 5
If s Then strReturn = "frmRecurrencePatternYearly"
End Select
If s Then
GetRecurrenceType = strReturn
Else
If Instance Then r = r + 1
GetRecurrenceType = "UPDATE tblAppointmentsRecurring SET " & _
"RecurrenceType = " & r & " WHERE ApptRcr_ID = " &
Me.ApptRcr_ID
End If
End Function 'jumps to End Select if case was 255

Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
It's going to the next statement in the invocation that called the invocation
that just completed. In VB/VBA, the debugger treats End Select as a statement
to step through after the final statement in a case block. Look at the call
stack at key points as you go, and all should become clear.

On Mon, 27 Dec 2004 01:32:21 GMT, "deko"
<www.clearpointsystems.com@use_contact_form.com> wrote:
When I loop through this function, it works fine until it hits End
Function - then it jumps to End Select. Very strange... This behavior
occurs when Case = 255. Any ideas why this is happening? Why doesn't the
function just end? Why the jump back in at End Select?

Thanks in advance.

Private Function GetRecurrenceType(r As Long, Optional s As Boolean) As
String
Dim strReturn As String
Select Case r
Case Is = 255
GetRecurrenceType =
GetRecurrenceType(Nz(DLookup("RecurrenceTypeDispl ay", _
"tblAppointmentsRecurring"), 2), True)
Case Is = 1
If s Then strReturn = "frmRecurrencePatternWeely"
Case Is = 2
If s Then strReturn = "frmRecurrencePatternMonthly"
Case Is = 5
If s Then strReturn = "frmRecurrencePatternYearly"
End Select
If s Then
GetRecurrenceType = strReturn
Else
If Instance Then r = r + 1
GetRecurrenceType = "UPDATE tblAppointmentsRecurring SET " & _
"RecurrenceType = " & r & " WHERE ApptRcr_ID = " &
Me.ApptRcr_ID
End If
End Function 'jumps to End Select if case was 255


Nov 13 '05 #2

P: n/a
> It's going to the next statement in the invocation that called the
invocation
that just completed. In VB/VBA, the debugger treats End Select as a statement to step through after the final statement in a case block. Look at the call stack at key points as you go, and all should become clear.


Thanks for the reply. I figured it had something to do with the Function
being self-recursive. But how do I deal with this? Do I need to change the
logic, or just add code after End Select? I guess I'm wondering if this
behavior is by design or a result of a coding error.
Nov 13 '05 #3

P: n/a
On Mon, 27 Dec 2004 05:47:11 GMT, "deko"
<www.clearpointsystems.com@use_contact_form.com> wrote:
It's going to the next statement in the invocation that called the

invocation
that just completed. In VB/VBA, the debugger treats End Select as a

statement
to step through after the final statement in a case block. Look at the

call
stack at key points as you go, and all should become clear.


Thanks for the reply. I figured it had something to do with the Function
being self-recursive. But how do I deal with this? Do I need to change the
logic, or just add code after End Select? I guess I'm wondering if this
behavior is by design or a result of a coding error.


Well, I'm not sure what you are saying is a problem. In a recursive
procedures, after one invocation exits, the next statement is the statement
following the call to that invocation in the calling invocation. That is as
expected, right?

Perhaps, I do not understand where your difficulty lies.
Nov 13 '05 #4

P: n/a
> Well, I'm not sure what you are saying is a problem. In a recursive
procedures, after one invocation exits, the next statement is the statement following the call to that invocation in the calling invocation. That is as expected, right?

Perhaps, I do not understand where your difficulty lies.


I'm not sure.... I ended up using different code. But thanks for the help.
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.