Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with Replace

Status
Not open for further replies.

exodus300

Programmer
Mar 22, 2002
262
0
0
AU
I am having problems with the following bit of code:
Code:
Function FormatMessage(strSource)
	strNewSource = strSource
	'FormatMessage = strNewSource
	'Exit Function
	
	'Response.Write "Raw message is:<blockquote>" & strNewSource & "</blockquote>"

	Set rs_format = Server.CreateObject("ADODB.RecordSet")
	rs_format.Open "SELECT * FROM Smileys", db
	Do While Not rs_format.EOF
		strSmileyCode = rs_format("SmileyCode")
		strFileName = rs_format("FileName")
		strAltText = rs_format("Description")
		
		' Replace the smiley code with the <img> tag
		strHtml =  "<img src=""images/smileys/" & strFileName & """ alt=""" & strAltText & """>"
		'Response.Write strNewSource
		strNewSource = Replace(strNewSource, strSmileyCode, strHtml)
		
		'Response.Write "Message after processing " & strSmileyCode & " is: <blockquote>" & strNewSource & "</blockquote>"
		rs_format.MoveNext
	Loop
	rs_format.Close
	Set rs_format = Nothing
	
	' Return the formatted message
	FormatMessage = strNewSource
End Function

The error message I am getting is:

Error Type:
Microsoft VBScript runtime (0x800A005E)
Invalid use of Null: 'Replace'
/forum/formatmessage.asp, line 20


If I change the Replace line to this:
Code:
strNewSource = Replace("bla bla bla :cool", strSmileyCode, strHtml)
... it works perfectly (replacing ":cool" with an html image tag).

Doing a Response.Write of strNewSource on the line before Replace shows that there is text in the string.


Please help me as this is very frustrating. Thank you.

[Thanks in advance|Hope I helped you]
Exodus300
[pc3]
 
If NOT IsNull(strNewSource) Then
strNewSource = Replace(strNewSource, strSmileyCode, strHtml)
Else
Response.Write "Nothing to replace"
End if
 
cool, but weird...

I changed the line to what you suggested. If strSmileyCode is in strNewSource, then it does the Replace, otherwise it goes to the Else part.

err... I just noticed. It works when there's one smiley. But when I used a string with two smileys, I get this:

Error Type:
(0x80020009)
Exception occurred.
/forum/showthread.asp, line 139

Note that line 139 is a totally unrelated line way further down in the script. FYI, it is
Code:
If rs_user("Glow") = True Then

[Thanks in advance|Hope I helped you]
Exodus300
[pc3]
 
thats strange, it must work.

try a plain stmt:
str=replace(":cool asdasd :cool",":cool",strSmiley)
response.write str

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top