I have a problem with a recursive function in one of my macros. The function 
is supposed to either return an array of strings or Empty (in case there's 
not enough input data). However, under some circumstances the function 
mysteriously returns Object/Null instead of Variant/Empty. I'd like to know 
if this is a bug in OOo (I tested 1.9.122 and 1.9.125) or some 
misunderstanding on my part. The following is a chopped down version of my 
code:

Sub Main
Dim n(1) as String
n(0) = " "
n(1) = " "
Dim a as Variant

f(Array(60,10,1,12,20,10,25,30), n(), 0, 76)

End Sub

Function f(splitInfo() as Variant, daten() as String, i as Long, j as Long) 
as Variant
If i > UBound(daten) Then
Exit Function
End If

Dim ret() as String

for k = 0 to UBound(splitInfo)
restLen = Len(daten(i)) - j
Dim splitPos as Long
splitPos = splitInfo(k)
If splitPos <= restLen Then
j = j + splitPos
Else
st = Right(daten(i), restLen)
i = i + 1
j = 0
sta = f(Array(splitPos - restLen), daten, i, j)

If IsNull(sta) Then
MsgBox("This is impossible!")
Exit Function
End if

End If
next k

f = ret()
End Function

As you can see there are only 2 ways out of the function f(). The first one 
is an "Exit Function" that is called without an assignment to the function's 
return value. On this code path the function is supposed to return 
Variant/Empty. The 2nd way out of the function is after the assignment f = 
ret() which sets the return value to an array of string. There should be no 
way for the function to return Variant/Null, so the condition IsNull(sta) 
should never be true. But strangely it is at some point. If I call the 
function directly from Main with the exact same parameters as the recursive 
call that returns Null, I get Empty as it should be. So it seems that Null 
is returned only in the recursive case.

Can someone give me a clue what's going on? Is this a bug? Should I file a 
bug report?

Matthias

Reply via email to