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
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…
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.