BUG? - with the LotusScript Replace Function

The following code causes NSD type error on client versions 6.5.2 / 6.5.3 / 6.5.4.

I’m sure I’ve used this function before but I don’t seem to be able to get this working.

Thanks in advance for any suggestions…

Kev


'REPLACE TEST:

Option Public

Sub Initialize

Dim strParam(0) As String

Dim strFrom(0) As String

Dim strTo(0) As String

Dim varDecoded As Variant



strParam(0) = "Simons%20Group"

strFrom(0) = "%20"

strTo(0) = "ASPACE"



varDecoded = fntDecode (strParam,strFrom,strTo)

End Sub

Function fntDecode (s As Variant, f As Variant, t As Variant) As Variant

fntDecode = Replace(s, f, t) 

End Function

Subject: BUG? - with the LotusScript Replace Function.

Have you tried writing the code to not have so many data type inconsistencies?

For example, I bet it would work by declaring you function as:

fntDecode (s As String, f As String, t As String) As String

Subject: Don’t know why it would work any better…

From the help for Replace:Replace(sourceArray as Variant, findArray as Variant, replacementArray as Variant[, start as Integer[, count as Integer[, compMethod as Integer]]]) as Variant

Subject: RE: Don’t know why it would work any better…

I think you are missing the point. If that is the declaration, declare everything as Variants, then…

The point is to have your data types match all the way through.

Subject: RE: Don’t know why it would work any better…

Replace is meant to work with Variant arrays containing strings throughout (except for count & compmethod) and returns a Variant array of strings. Use of Variants here is proper, correct, and (as a bonus) also the right thing to do. The function return, at least, cannot be implicitly converted to a string, although all of the inputs can be implicitly converted to Variants.

Subject: RE: Don’t know why it would work any better…

I did try sending Strings to the function and that worked ok. But that makes the replaces pretty limited, and as you say the documentation suggest that variants are allowed

Subject: BUG WORKAROUND - with the LotusScript Replace Function.

This happened to me on two different platforms for two different employers and two different bases (client and web) and I finally determined that the first parameter of the LotusScript Replace command cannot be an argument of the sub (or function). If it is it crashes the server, if it isn’t it works perfectly.

So instead of:

Function fntDecode (s As Variant, f As Variant, t As Variant) As Variant

fntDecode = Replace(s, f, t)

End Function

…simply code as:

Function fntDecode (s As Variant, f As Variant, t As Variant) As Variant

Dim s2 as variant

s2 = s

fntDecode = Replace(s2, f, t)

End Function

…and the problem goes away. Wow! Maybe it is fixed in later versions. I am using 6.5 September 2003 and my other employer was 6.5.2.

Subject: BUG WORKAROUND - MORE PROBLEMS with the LotusScript Replace Function.

I have also found out that the all three parameters must be local. And don’t think you can just copy global or argument arrays to local variants, because (as I found out by crashing the server again) all you are doing is reassigning the same global pointer to a local variable. Down comes the server.

Subject: BUG? - with the LotusScript Replace Function.

It kills 6.0.4 clients as well. If you put the replace in the init function and not in the fntDecode it works fine. Spooky!!

I suggest you raise and PRM bug report.

AJP

Subject: BUG? - with the LotusScript Replace Function.

I ran into another version of this bug.

Assume your ‘Source’ and ‘To’ arrays are strings.

Assume also, that you want to prompt the user for the ‘From’ list.

ws.Prompt returns a variant.

If you do

Replace(Source, From, To) your passing in

Replace(String,Variant,String) and NSD is the outcome.

If you convert the ‘From’ variant into an array, everything works.

Forall o in From

FromStringArray(j) = o

j = j + 1

Redim Preserve FromStringArray(j)

End Forall

j = j - 1

Redim Preserve FromStringArray(j)

Replace(Source,FromStringArray,To) - this works great

I tried creating Source, From, and To as variants, big old NSD on that.

Hope this helps someone.

Doug