• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 319
  • Last Modified:

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
0
Steven Wells
Asked:
Steven Wells
1 Solution
 
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
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
 
Steven WellsSystems AdministratorAuthor Commented:
Thanks. I will incorporate this. It makes it easy to add lots more tags too.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now