Forum Moderators: open
The next step is the problem. Using the ASP fileSystem I open the HTML file on the sever and write the HTML to a variable. Then open a recordset and pull the hrefs out of the databse that match this newsletterID. The object of the whole exercise is to find the original a hrefs in the HTML and replace them with the new hrefs which contain tracking information to track what links the user clicked on etc.
When I try to create a loop to replace the oldhrefs with the newhrefs I can not get it to loop and replace with the new links. Here's a sample of the code..
set objFS = Server.CreateObject("Scripting.FileSystemObject")
dim vartextfile
vartextfile = "c:\inetpub\wwwroot\expo\Campaign_archives\expoDirect41020200313417.htm"
set objFile = objFS.GetFile(vartextfile)
set objTS = objFile.OpenAsTextStream(ForReading, TristateFalse)
strSearchThis = objTS.Read(objFile.Size)
for x=1 to 4
'
while not gethtmltextfiles.EOF
newhtml = (gethtmltextfiles("tl_URLnew"))
oldhtml = (gethtmltextfiles("tl_URL" ))
strHTMLSOURCE1 = Replace (strSearchThis, oldhtml, newhtml )
gethtmltextfiles.MoveNext
wend
next
there are 4 records in the Db that match the newsletterID and I just hacked the For x loop to return 4 loops for now.
Can anybody offer suggestions as to the best way to achieve this looped recordset/text file replace function?
dim old(2)
dim new(2)
old(0) = "oldlink.html"
old(1) = "anotheroldlink.html"
new(0) = "newlink.html"
new(1) = "anothernewlink.html"
c = 0
while c < ubound(old)
strHTMLSOURCE1 = Replace (strSearchThis, old(c), new(c))
c = c + 1
wend
then put the records into a variable
var_oldhtml = objRs("oldhtml")
var_newdhtml = objRs("newhtml")
then I try to loop through the recordset replaceing the instance of the oldhtml in the text file with the newhtml until all the links are replaced.
while not gethtmltextfiles.EOF
newhtml = gethtmltextfiles.Fields.item("tl_URLnew").value
oldhtml = gethtmltextfiles.Fields.item("tl_URL").value
strHTMLSOURCE1 = (Replace(strSearchThis, oldhtml , newhtml ))
gethtmltextfiles.MoveNext
wend
only replaces the last record in the dataset. If I have 4 links the last one is replaced but the other 3 are not?
var_oldhtml = objRs("oldhtml")
var_newdhtml = objRs("newhtml")
then I try to loop through the recordset replaceing the instance of the oldhtml in the text file with the newhtml until all the links are replaced.
while not objRs.EOF
strHTMLSOURCE1 = (Replace(strSearchThis, oldhtml , newhtml ))
objRs.MoveNext
wend
sorry!
(old)http://www.computerexpo.com.au/link2.asp
(new)http://www.computerexpo.com.au/admin/trans.asp?transid=414&nlid=515&userid=¦userid¦
(old)http://www.computerexpo.com.au/link3.asp
(new)http://www.computerexpo.com.au/admin/trans.asp?transid=415&nlid=515&userid=¦userid¦
(old)http://www.computerexpo.com.au/link4.asp
(new)http://www.computerexpo.com.au/admin/trans.asp?transid=416&nlid=515&userid=¦userid¦
this is what the recordset returns to get the oldhtml and the newhtml. There are 4 links in this newsletter
tempstring = strSearchThis
while not objRs.EOF
var_oldhtml = objRs("oldhtml")
var_newdhtml = objRs("newhtml")
tempstring = (Replace(tempstring, var_oldhtml , var_newhtml ))
objRs.MoveNext
wend
strHTMLSOURCE1 = tempstring
"The correct code"
Do while not gethtmltextfiles.EOF
newhtml = gethtmltextfiles("tl_URLnew")
oldhtml = gethtmltextfiles("tl_URL")
strSearchThis= Replace(strSearchThis, oldhtml,newhtml)
gethtmltextfiles.MoveNext
Loop
response.write strSearchThis