1
VB and the development of wizards / Reentrant code
« on: March 03, 2008, 05:52:06 AM »
VB functions and subroutines should allocate local variables on the stack so that they can be called reentrantly. Cypress doesn't seem to be doing this. My current code is rather long to post here, but essentially I'm trying to do something like this:
sub divide(byval a as double, byval b as double)
Dim c as double
if abs(b-a)>0.1 then
c=(a+b)/2
divide (a,c)
divide (c,b)
else
Code "G1 X" & b
end if
end sub
What happens is that, after the first recursive call to divide(a,c), c gets set to 0 so the second call is divide(0,d), not divide(c,d). Indeed, the values of all local variables get reset to 0 after the first recursive call. I could recalculate them but that really shouldn't be necessary.
Have I missed something you need to do in VB to make routines recursive? Or is this a bug?
Thanks for any input
Chris Lusby Taylor
sub divide(byval a as double, byval b as double)
Dim c as double
if abs(b-a)>0.1 then
c=(a+b)/2
divide (a,c)
divide (c,b)
else
Code "G1 X" & b
end if
end sub
What happens is that, after the first recursive call to divide(a,c), c gets set to 0 so the second call is divide(0,d), not divide(c,d). Indeed, the values of all local variables get reset to 0 after the first recursive call. I could recalculate them but that really shouldn't be necessary.
Have I missed something you need to do in VB to make routines recursive? Or is this a bug?
Thanks for any input
Chris Lusby Taylor