Gerald Ferreira
Gerald Ferreira

Reputation: 1337

Simple Regex Replace Visual Script

I have the following code

<% 
txt = ""+(rs_email.Fields.Item("g_email_body").Value)+""
Set objReg = CreateObject("vbscript.regexp")
objReg.Pattern = "[activate]"
activate = (objReg.Replace(txt,"http://www.gamtool.com/activate.asp?id="+(Recordset1.Fields.Item("g_userbase_id").Value)+""))
%>

When I run the code I get an error on the last line

activate = (objReg.Replace(txt,"http://www.gamtool.com/activate.asp?id="+(Recordset1.Fields.Item("g_userbase_id").Value)+""))
    %>

any ideas why I am getting the error?

I have updated the code above to the following:

<%
  Set regEx = New RegExp
  regEx.Global = true
  regEx.IgnoreCase = True
  regEx.Pattern = "\[activate\]"
  strText = ""+(rs_email.Fields.Item("g_email_body").Value)+""
  activate = regEx.Replace(strText, ""+(Recordset1.Fields.Item("g_userbase_id").Value)+"")
%>

If I change the ""+(Recordset1.Fields.Item("g_userbase_id").Value)+"") to any value but insert the value static then it works.

Thanks

Upvotes: 1

Views: 1191

Answers (1)

stealthyninja
stealthyninja

Reputation: 10371

@Gerald Ferreira: Instead of using +, use & to concatenate. You're getting the type mismatch error because VB Script thinks you're trying to add which, of course, isn't the same as concatenating.

Upvotes: 1

Related Questions