What is wrong with this code?

I get this error: (Global): Replace: 1: Unexpected: Replace; Expected: Identifier

Here is the code:

Public Function Replace( Byval InString, Byval ReplString, Byval WithString )

 'Purpose: Replaces all occurrences of <ReplString> in <InString> with <WithString>

 On Error Goto TrapError



 While Not InString = ""

      If Left( InString, Len( ReplString ) ) = ReplString Then

           Result = Result & WithString

           InString = Right( InString, Len( InString ) - Len( ReplString ) )

      Else

           Result = Result & Left( InString, 1 )

           InString = Right( InString, Len( InString ) -1 )

      End If

 Wend



 Replace = Result

 Exit Function

TrapError:

 Replace = InString

 Exit Function

End Function

Subject: what is wrong with this code?

Hello

The function Replace does exist in Notes 6

“”

Replace(sourceArray as Variant, findArray as Variant, replacementArray as Variant[, start as Integer[, count as Integer[, compMethod as Integer]]]) as Variant

“”

so to solve this yopu should rename the function to sReplace or something

regards toine

Subject: The other way this error message happens

For the benefit of other searchers like me for whom this is the most relevant thread searching on “Replace” and “Unexpected” : This message also results if you use “Replace” as a subroutine as in

Replace( Values, aFrom, aTo )

  or 

Call Replace( Values, aFrom, aTo )

You have to code

Values = Replace( Values, aFrom, aTo )

Subject: what is wrong with this code?

Replace is a Lotusscript function. Call your function something else.

You should also be more clear about whether the error occurs at compile-time or at run-time.

Replace(sourceArray as Variant, findArray as Variant, replacementArray as Variant[, start as Integer[, count as Integer[, compMethod as Integer]]]) as Variant

Subject: Preventing Routine name Collisions with LotusScript Statements

If you need a x-releases (e.g. R4, R5, R6) compatible Replace() function, you can wrap it within a class and use it as follows:

Dim f as New myFunctions

msgbox f.Replace( “Source”, “from”, “to” )( 0 )

Your clas may ressemble something like:

Class myFunctions

Public Function Replace( Byval InString, Byval ReplString, Byval WithString )

Dim v

’ Your code goes here

Me.Replace = v

End Function

End Class

Subject: what is wrong with this code?

Starting from Notes6, there is a built-in Replace function.That makes “Replace” a reserved word.

(Maybe you don’t need your own function anymore ?)