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
LVL 12
Steven WellsSystems AdministratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Om PrakashCommented:
You can create an array of tags and then using loop you can find and replace the content which you got from database.
0
Steven WellsSystems AdministratorAuthor Commented:
Sounds like a good start, are you able to give quick example?
0
Patrick MatthewsCommented:
Post the working code you have so far, and it should be pretty easy to incorporate an array with loop.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Steven WellsSystems AdministratorAuthor Commented:
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?
0
CodeCruiserCommented:
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
0
Patrick MatthewsCommented:
Dim arr, Counter

ReDim arr(5, 1)
arr(0, 0) = "%displayName%"
arr(0, 1) = SDisplayName
arr(1, 0) = "%FltNo%"
arr(1, 1) = sFltNo
arr(2, 0) = "%PriDesc%"
arr(2, 1) = sPriDesc
arr(3, 0) = "%FlTDesc%"
arr(3, 1) = sFlTDesc
arr(4, 0) = "%FltOpen%"
arr(4, 1) = sFltOpen
arr(5, 0) = "%UpdateLink%"
arr(5, 1) = sUpdateLink

supdattext = GetEmailText(1)
For Counter = LBound(arr, 1) To UBound(arr,1)
    supdattext = Replace(supdattext, arr(Counter, 0), arr(Counter, 1))
Next

WScript.Echo supdattext
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steven WellsSystems AdministratorAuthor Commented:
Thanks. I will incorporate this. It makes it easy to add lots more tags too.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.