RegEx.Pattern trouble writing to txt file

If I use the function
' ------------
Function RemoveHTML( varCopy )
      Dim RegEx

      Set RegEx = New RegExp

      RegEx.Pattern = "<[^>]*>"
      RegEx.Global = True

      RemoveHTML = RegEx.Replace(varCopy, "")
End Function
newVarCopy = RemoveHTML(varCopy)
' ---------------
and response.write the results to the browser, I have no problems. But, If I try to write to a txt file, I get the error message of:

Microsoft VBScript compilation  error '800a03ea'
Syntax error
/pricerunner/index2.asp, line 32
Function RemoveHTML( varCopy )
^

I am using
' -----------------
' varCopy is already defined from rs
file_being_created= "pricerunner_" & Replace(FormatDateTime(Date(),2),"/","") & ".txt"
set fso = createobject("scripting.filesystemobject")
Set act = fso.CreateTextFile(server.mappath(file_being_created), true)

Function RemoveHTML( varCopy )
      Dim RegEx

      Set RegEx = New RegExp

      RegEx.Pattern = "<[^>]*>"
      RegEx.Global = True

      RemoveHTML = RegEx.Replace(varCopy, "")
End Function

strLine = "first line" & Chr(13)
strLine = strLine & "second line" & Chr(13)
strLine = strLine & RemoveHTML(varCopy) & Chr(13)

act.WriteLine(strLine)
' --------------------

is this not a valid use of this function? Is there another way to get the results I am looking for? Basically, I am taking descriptive product copy that contains html tags and am trying to strip the tags out and output to a text file for a datafeed. I can do this with a series of Replace statements but am concerned about missing some.

Thanks!
LVL 1
shadieAsked:
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.

WMIFCommented:
try using .write instead of .writeline.  you may be running against the line breaks in your string or something.
0
kevp75Commented:
i've run into this before.

What I did, was moved the function out of the code and into an included file.

@WMIF, doesn't .writeline write a line to the text file? and .write is for display only?
0
WMIFCommented:
writeline puts whatever you pass into the text file and writes a crlf after that data.  

write puts what you pass only.

http://www.w3schools.com/asp/asp_ref_textstream.asp
scroll down to methods.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

kevp75Commented:
ahh.

Now, will .write recognize a line break if it is coded into what is to be written?
0
WMIFCommented:
it wont recognize anything, it just writes to the file whatever it gets.  by recognize do you mean, will the break be written to the file?  if so, then yes it will be written just as its passed.
0
kevp75Commented:
yes WMIF, that is what I meant by recognize...

so...would it really make a difference if the asker user .write as opposed to .writeline...   seems that .writeline would just put in a line break after the data is written along with the line breaks in the existing code., and .write would just skip out on that last line break?

@shadie
without building a db to pull data from, I've tried your code, and it seems that moving the function is the way to go.  Basically all I did was:

dim varCopy
varCopy = "<html><body><font face="verdana" size="10">Some text<br>to write</font></body></html>"
Function RemoveHTML( varCopy )
     Dim RegEx

     Set RegEx = New RegExp

     RegEx.Pattern = "<[^>]*>"
     RegEx.Global = True

     RemoveHTML = RegEx.Replace(varCopy, "")
End Function
file_being_created= "pricerunner_" & Replace(FormatDateTime(Date(),2),"/","") & ".txt"
set fso = createobject("scripting.filesystemobject")
Set act = fso.CreateTextFile(server.mappath(file_being_created), true)

strLine = "first line" & Chr(13)
strLine = strLine & "second line" & Chr(13)
strLine = strLine & RemoveHTML(varCopy) & Chr(13)

act.WriteLine(strLine) 'changing this to .write has the same basic effect, except .writeline put in an extra line break
0
WMIFCommented:
>>so...would it really make a difference if the asker user .write as opposed to .writeline...  

i dont know, that is why i suggested that the asker try it.  i dont have a server available to me as of right now to test.  apparently you did and answered the question.


@shadie - something else i just caught could be the use of similar variable names.  try changing the argument of your function to have a different variable name.

Function RemoveHTML( inputCopy )
RemoveHTML = RegEx.Replace(inputCopy, "")
0
shadieAuthor Commented:
kevp,
I call this the real estate function -- because it's all about location, location, location...

I was all set to give you the nod for your answer as I changed the location of that function and the page loaded without errors. It produced the file and I thought I was done.

I then went into the data and found that moving the function to before I declare the filesystemobject, that that also removed the "dim varCopy" to outside of the rs loop. So all the records output to the file are the same record instead of the loop. Any thoughts?
0
kevp75Commented:
you mention loop, I do not see one posted in your code above.    Please post it.
0
shadieAuthor Commented:
rs select HERE..

file_being_created= "pricerunner_" & Replace(FormatDateTime(Date(),2),"/","") & ".txt"
set fso = createobject("scripting.filesystemobject")
Set act = fso.CreateTextFile(server.mappath(file_being_created), true)

strLine = "category||sku||price||product URL||product name||product state||manufacturer SKU||manufacturer||in stock||stock level||delivery time||shipping cost||description||craphic URL"
strLine = strLine & Chr(13)

while not rs.eof

dim varCopy
varCopy = rs("copy")
Function RemoveHTML( varCopy )
     Dim RegEx

     Set RegEx = New RegExp

     RegEx.Pattern = "<[^>]*>"
     RegEx.Global = True

     RemoveHTML = RegEx.Replace(varCopy, "")
End Function

if varCopy <> "" then
-- a bunch of other strLine = strLine & ... HERE

end if
rs.movenext
wend

act.WriteLine(strLine)
0
kevp75Commented:
that looks like you didn't move anything?

move the dim varCopy, and the function to the top of your page, keep varCopy = rs("copy") where it is
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
shadieAuthor Commented:
oooof -- I can be such an idiot sometimes!

I did move the code per your previous post and found that it worked without error but found that no-loop problem. I put the function back in the loop and that's where I commented last. When I sent you over that last block of code, it was the version with the function in the loop, not outside.

Regardless, I moved the function to the top of the page and variable declaration. I followed up with the rs and FSO then started my writeLine loop and it looks like all is well.

Thanks for the help!
0
kevp75Commented:
np...glad I could help
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
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.