Link to home
Start Free TrialLog in
Avatar of Steven Wells
Steven WellsFlag for Australia

asked on

Replace tag list with words

Hi,
I am working on some vbscript where I want to have a set list of tags that people can use to customise an automated email. So far I have about 5 tags that are in the format of %username%, %TicketNo% etc. These are then substitued for the real values.

I am trying to come up with a nice way of replacing the %tagname% with the value from the database. Currently I am using the vb replace, but with 5 tags that is ok, but I want to use about 15-20. I was thinking there must be a better way of loading the tag list into some function and use that.

The script is vbs, however happy to rewrite if VB.net has a better solution (on my list of things to do)

Any ideas on a better way to achive this?

Steve
Avatar of Om Prakash
Om Prakash
Flag of India image

You can create an array of tags and then using loop you can find and replace the content which you got from database.
Avatar of Steven Wells

ASKER

Sounds like a good start, are you able to give quick example?
Avatar of Patrick Matthews
Post the working code you have so far, and it should be pretty easy to incorporate an array with loop.
Ok,
So currently I have a string that has all the tags inside

supdattext = GetEmailText(1)
supdattext = (Replace(supdattext,"%displayName%",SDisplayName))
supdattext = (Replace(supdattext,"%FltNo%",sFltno))
supdattext = (Replace(supdattext,"%PriDesc%",sPriDesc))
supdattext = (Replace(supdattext,"%FlTDesc%",SFlTDesc))
supdattext = (Replace(supdattext,"%FltOpen%",sFltOpen))
supdattext = (Replace(supdattext,"%UpdateLink%",Updatelink))


WScript.Echo supdattext

I think I need to load all %words% into an array and then subsitute with it's correct value.

Any ideas?
May be you can write a function which accepts the parameter and returns the actual string

So replace %username% with %GetValue("username")%

Private Function GetValue(input as String) As String
   If input = "username" Then
      Return ...
   ElseIf input = "ticketno" Then
      Return ...
   ...
   End If
End Function
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks. I will incorporate this. It makes it easy to add lots more tags too.