473,386 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

recursive function fails to return value

Expand|Select|Wrap|Line Numbers
  1. Function recursiveTest(n)
  2.     x = n + 1
  3.     Debug.Print n
  4.     If x > 10 Then
  5.         recursiveTest = "finish recursive test"
  6.     Else
  7.         recursiveTest x
  8.     End If
  9. End Function
If I debug, I don't see the "finish recursive test".
? recursiveTest(7,false)
7
8
9
10
<blank>

I should see "finish recursive test" instead of the whilte blank line there.
Oct 24 '07 #1
2 1418
kadghar
1,295 Expert 1GB
...
i should see "finish recursive test" instead of the whilte blank line there.
Try to define better the variables you're using, I hope your problem could solve if you define, and evaluate strings.
Expand|Select|Wrap|Line Numbers
  1. function recursiveText( byval n as string) as string
  2. dim x as double
  3. x = val(n) +1 
... and everything else. Give it a try

HTH
Oct 24 '07 #2
Killer42
8,435 Expert 8TB
? recursiveTest(7,false)
7
8
9
10
<blank>

I should see "finish recursive test" instead of the whilte blank line there.
Are you sure the Debug output you're showing us matches the code listed above? You have two parameters there, while the function declaration has only one. Surely that should produce an error.

Also, there's no reason why you should see that text come back. Only the last "recursion" returns that value. It is then discarded when you "back out" to the next level. In other words, when it passes 10, it returns your string. The next level up, which called it, simply returns then without setting any return value. Try this on line 7, and see what happens...

Expand|Select|Wrap|Line Numbers
  1. recursiveTest = recursiveTest(x)
Oct 25 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Derek Rhodes | last post by:
using Python 2.3.4 (#53, May 25 2004, 21:17:02) on win32 OK, I have a recursive function that should return a list, but doesn't <start session> def test(word): if type(word) == str:
2
by: | last post by:
OK: Purpose: Using user's input and 3 recursive functions, construct an hour glass figure. Main can only have user input, loops and function calls. Recursive function 1 takes input and displays...
4
by: Victor | last post by:
Hello, I've got a situation in which the number of (valid) recursive calls I make will cause stack overflow. I can use getrlimit (and setrlimit) to test (and set) my current stack size. ...
5
by: Seong-Kook Shin | last post by:
Hi, I'm reading Steve's "C Programming FAQs" in book version, and have two question regarding to Q11.16 ... Also, a `return' from `main' cannot be expected to work if data local to main might be...
11
by: randomtalk | last post by:
hi, i have the following recursive function (simplified to demonstrate the problem): >>> def reTest(bool): .... result = .... if not bool: .... reTest(True) .... else: .... print...
4
by: Gregory Piñero | last post by:
Hi, Would anyone be able to tell me why my function below is getting stuck in infinite recusion? Maybe I'm just tired and missing something obvious? def...
10
by: AsheeG87 | last post by:
Hello Everyone! I have a linked list and am trying to include a recursive search. However, I am having trouble understanding how I would go about that. I don't quite understand a recursive...
9
by: pereges | last post by:
Hello I need some ideas for designing a recursive function for my ray tracing program. The idea behind ray tracing is to follow the electromagnetic rays from the source, as they hit the...
3
by: from.future.import | last post by:
Hi, I encountered garbage collection behaviour that I didn't expect when using a recursive function inside another function: the definition of the inner function seems to contain a circular...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.