Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

VB6 Help out of stack

  1. Jan 10, 2009 #1


    User Avatar
    Gold Member

    VB6 Help out of stack"

    I was writing a program to work out factorials of large numbers. The doubble varible over flows at 9E+308. I work out some of the factorial then move to another subroutine and devide by ten untill it is < 10 then continue timising it by integers. In the end I am left with a decimal number < 10 and another number which represents the exponant.

    If I try to find the factorial of a very large number (200000+) it gives me an error "out of stack space", which I think is because it creats a stack to keep track of when you move between subroutine. I use the Call command, does any one know a different command or a way to stop it running out of stack space?

  2. jcsd
  3. Jan 10, 2009 #2


    User Avatar
    Gold Member

    Re: VB6 Help out of stack"

    I assume your factorial is written using recursion (where a subroutine calls itself repeatedly). Each subroutine call adds all the local variables in your subroutine to the stack for each recursive call. So eventually there is not enough room in the computer's memory to stack anything more.

    It is usually possible to solve "recursive" algorithms in a program without actually using recursion. To do so, you'll need a huge 2-dimensional array. One dimension holds all the bookkeeping you would normally store in the local variables for one recursive call; the other dimension is used for the successive steps in the recursive algorithm. It's not at all clear that you would be able to compute the factorial of larger numbers this way, since it will also consume a lot of memory. That's because the algorithm itself is going to repeat about a gazillion steps (that's more than a brazillion, by the way).

    You might be able to do larger numbers by doubling the RAM (memory) in your computer. But you won't really get orders of magnitude improvement.
  4. Jan 10, 2009 #3


    User Avatar
    Gold Member

    Re: VB6 Help out of stack"

    I moved it all into one subroutine and it works very well, thanks for the help.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: VB6 Help out of stack
  1. A qustion in stacks (Replies: 3)

  2. Splitting String-VB6 (Replies: 1)

  3. VB6 Help (Replies: 6)