Why is this a compiler error

I have a local var

dim lsConfMsg as String

This blows up compiler with [quote]There is more than 1 item with this name and it’s not clear to which it refers[/quote]

  lsConfMsg.ToText.Replace(lsConfMsg, "#eduamountpaid#", rs.Field("Cost").StringValue)

And this doesn’t

lsConfMsg = Replace(lsConfMsg, "#eduamountpaid#", rs.Field("Cost").StringValue)

It doesn’t make sense to me, could someone explain this.


You are unnecessarily calling the Text version of Replace and giving it a String rather than Text in its second parameter. This confuses and angers the compiler.

Also, the result of a Replace, either as String or Text, must be assigned.

Try either of these instead:

lsConfMsg = lsConfMsg.Replace("#eduamountpaid#", rs.Field("Cost").StringValue)
lsConfMsg = lsConfMsg.ToText.Replace("#eduamountpaid#", rs.Field("Cost").StringValue.ToText)

The second version is for illustration of the point only. As I said, introducing the Text type here is unnecessary and probably slower.

Sometimes I have no idea where my brain went!

Thanks for pointing out the obvious!

I hate it when the compiler gets “angry”…

Worse yet is when you anger the programming gods.