Connecting Tech Pros Worldwide Help | Site Map

Smilie filter

Newbie
 
Join Date: Jul 2009
Posts: 8
#1: Jul 10 '09
hey there. im new to the coding side of asp as i learnt html before hand. What im trying to do is intergreat a smilie filter in to a small chat i building for me and and some mates. The chat is using a SQL database and IIS. my current source code for it is here:
Expand|Select|Wrap|Line Numbers
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
  2. <!--#include file="../../../../Connections/databasechat.asp" -->
  3. <%
  4. Dim chatmsg__MMColParam
  5. chatmsg__MMColParam = "3"
  6. If (Request("MM_EmptyValue") <> "") Then 
  7.   chatmsg__MMColParam = Request("MM_EmptyValue")
  8. End If
  9. %>
  10. <%
  11. Dim chatmsg
  12. Dim chatmsg_numRows
  13.  
  14. Set chatmsg = Server.CreateObject("ADODB.Recordset")
  15. chatmsg.ActiveConnection = MM_databasechat_STRING
  16. chatmsg.Source = "SELECT * FROM dbo.TBLmainroom WHERE TBLroom = '" + Replace(chatmsg__MMColParam, "'", "''") + "' ORDER BY ID DESC"
  17. chatmsg.CursorType = 0
  18. chatmsg.CursorLocation = 2
  19. chatmsg.LockType = 1
  20. chatmsg.Open()
  21.  
  22. chatmsg_numRows = 0
  23. %>
  24. <%
  25. Dim Repeat1__numRows
  26. Dim Repeat1__index
  27.  
  28. Repeat1__numRows = 100
  29. Repeat1__index = 0
  30. chatmsg_numRows = chatmsg_numRows + Repeat1__numRows
  31. %>
  32. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  33. <html xmlns="http://www.w3.org/1999/xhtml">
  34. <head>
  35. <%Response.Expires=-1%>
  36. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  37. <title>Untitled Document</title>
  38. <script>
  39. <!--
  40. function timedRefresh(timeoutPeriod) {
  41.     setTimeout("location.reload(true);",timeoutPeriod);
  42. }
  43. //   -->
  44. </script>
  45. <title>Untitled Document</title>
  46. <style type="text/css">
  47. <!--
  48. body {
  49.     margin: 0px 0px 0px 0px;
  50. .style2 {color: #0000FF}
  51. .style3 {
  52.     font-size: 9px;
  53.     font-family: Arial, Helvetica, sans-serif;
  54. }
  55. .style6 {color: #FF00FF}
  56. .style7 {font-family: Arial, Helvetica, sans-serif}
  57. .style8 {
  58.     color: #FFFFFF;
  59.     font-style: italic;
  60. }
  61. .style10 {
  62.     font-family: Arial, Helvetica, sans-serif;
  63.     font-weight: bold;
  64.     font-style: italic;
  65.     color: #FF00FF;
  66. }
  67. -->
  68. </style>
  69. </head>
  70. <body onload="javascript:timedRefresh(3000);">
  71. <% If Not chatmsg.EOF Or Not chatmsg.BOF Then %>
  72.   <% 
  73. While ((Repeat1__numRows <> 0) AND (NOT chatmsg.EOF)) 
  74. %>
  75.     <strong><span class="style7"><font color="#00FF00"><%=(chatmsg.Fields.Item("TBLuser").Value)%></font></span></span> </strong><span class="style7"></span>
  76.     <span class="style7"><font color="#9900FF"><%=(chatmsg.Fields.Item("TBLmessage").Value)%></font></span><br />
  77.     <% 
  78.   Repeat1__index=Repeat1__index+1
  79.   Repeat1__numRows=Repeat1__numRows-1
  80.   chatmsg.MoveNext()
  81. Wend
  82. %>
  83.   <% End If ' end Not chatmsg.EOF Or NOT chatmsg.BOF %>
  84. </body>
  85. </html>
  86. <%
  87. chatmsg.Close()
  88. Set chatmsg = Nothing
  89. %>
I want to post the smiles where the <%=(chatmsg.Fields.Item("TBLmessage").Value)%> is as this displays the message. Any ideas how i go about doing this as the chat does not have any filter yet. thanks in advance.
Newbie
 
Join Date: Jul 2009
Posts: 8
#2: Jul 10 '09

re: Smilie filter


hey there. im new to the coding side of asp as i learnt html before hand. What im trying to do is intergreat a smilie filter in to a small chat i building for me and and some mates. The chat is using a SQL database and IIS. my current source code for it is here:
Expand|Select|Wrap|Line Numbers
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
  2. <!--#include file="../../../../Connections/databasechat.asp" -->
  3. <%
  4. Dim chatmsg__MMColParam
  5. chatmsg__MMColParam = "3"
  6. If (Request("MM_EmptyValue") <> "") Then 
  7.   chatmsg__MMColParam = Request("MM_EmptyValue")
  8. End If
  9. %>
  10. <%
  11. Dim chatmsg
  12. Dim chatmsg_numRows
  13.  
  14. Set chatmsg = Server.CreateObject("ADODB.Recordset")
  15. chatmsg.ActiveConnection = MM_databasechat_STRING
  16. chatmsg.Source = "SELECT * FROM dbo.TBLmainroom WHERE TBLroom = '" + Replace(chatmsg__MMColParam, "'", "''") + "' ORDER BY ID DESC"
  17. chatmsg.CursorType = 0
  18. chatmsg.CursorLocation = 2
  19. chatmsg.LockType = 1
  20. chatmsg.Open()
  21.  
  22. chatmsg_numRows = 0
  23. %>
  24. <%
  25. Dim Repeat1__numRows
  26. Dim Repeat1__index
  27.  
  28. Repeat1__numRows = 100
  29. Repeat1__index = 0
  30. chatmsg_numRows = chatmsg_numRows + Repeat1__numRows
  31. %>
  32. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  33. <html xmlns="http://www.w3.org/1999/xhtml">
  34. <head>
  35. <%Response.Expires=-1%>
  36. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  37. <title>Untitled Document</title>
  38. <script>
  39. <!--
  40. function timedRefresh(timeoutPeriod) {
  41.     setTimeout("location.reload(true);",timeoutPeriod);
  42. }
  43. //   -->
  44. </script>
  45. <title>Untitled Document</title>
  46. <style type="text/css">
  47. <!--
  48. body {
  49.     margin: 0px 0px 0px 0px;
  50. .style2 {color: #0000FF}
  51. .style3 {
  52.     font-size: 9px;
  53.     font-family: Arial, Helvetica, sans-serif;
  54. }
  55. .style6 {color: #FF00FF}
  56. .style7 {font-family: Arial, Helvetica, sans-serif}
  57. .style8 {
  58.     color: #FFFFFF;
  59.     font-style: italic;
  60. }
  61. .style10 {
  62.     font-family: Arial, Helvetica, sans-serif;
  63.     font-weight: bold;
  64.     font-style: italic;
  65.     color: #FF00FF;
  66. }
  67. -->
  68. </style>
  69. </head>
  70. <body onload="javascript:timedRefresh(3000);">
  71. <% If Not chatmsg.EOF Or Not chatmsg.BOF Then %>
  72.   <% 
  73. While ((Repeat1__numRows <> 0) AND (NOT chatmsg.EOF)) 
  74. %>
  75.     <strong><span class="style7"><font color="#00FF00"><%=(chatmsg.Fields.Item("TBLuser").Value)%></font></span></span> </strong><span class="style7"></span>
  76.     <span class="style7"><font color="#9900FF"><%=(chatmsg.Fields.Item("TBLmessage").Value)%></font></span><br />
  77.     <% 
  78.   Repeat1__index=Repeat1__index+1
  79.   Repeat1__numRows=Repeat1__numRows-1
  80.   chatmsg.MoveNext()
  81. Wend
  82. %>
  83.   <% End If ' end Not chatmsg.EOF Or NOT chatmsg.BOF %>
  84. </body>
  85. </html>
  86. <%
  87. chatmsg.Close()
  88. Set chatmsg = Nothing
  89. %>
I want to post the smiles where the <%=(chatmsg.Fields.Item("TBLmessage").Value)%> is as this displays the message. Any ideas how i go about doing this as the chat does not have any filter yet. thanks in advance.
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#3: Jul 13 '09

re: Smilie filter


Quote:

Originally Posted by petvampire View Post

...
I want to post the smiles where the <%=(chatmsg.Fields.Item("TBLmessage").Value)%> is as this displays the message. Any ideas how i go about doing this as the chat does not have any filter yet. thanks in advance.

Hi Vamp, and welcome to Bytes.

A couple things before I get into your question: first, we use code tags to make our posts more readable, [ code ] code goes here [ /code ] (remove the spaces to see how it works), please do the same in the future. Second, the longhand you have used for pulling up the field value is very long. The following two lines are equivalent:
Expand|Select|Wrap|Line Numbers
  1. <%=(chatmsg.Fields.Item("TBLmessage").Value)%>
  2. <%=chatmsg("TBLmessage")%>
Hopefully if you figure that out now it will make your future coding a little easier.

So to make sure I understand you, when you response.write chatmsg("TBLmessage") you might get someting like this:
Expand|Select|Wrap|Line Numbers
  1. UR tre fun-E LOL :)
and you want the script to replace the last two characters with a smilie graphic, right?

The code to make the replacement is going to look something like this:
Expand|Select|Wrap|Line Numbers
  1. <%=replace(chatmsg("TBLmessage"), ":)", "<img src='smile1.gif'>")%>
Does this make sense? Now depending on the number of smileys you want to recognize you might want to make this significantly more complicated, maybe put the replace statement in a loop in a separate function call (and now my mind is going blank on how you write functions in ASP, something like this):
Expand|Select|Wrap|Line Numbers
  1. function smilify(chatText)
  2.    dim smileys(10)
  3.    dim smileyGraphics(10)
  4.    smileys(0) = ":)"
  5.    smileys(1) = ":S"
  6.    smileys(2) = ";)"
  7.    '...
  8.    smileyGraphics(0) = "<img src='smiley0.gif'>"
  9.    smileyGraphics(1) = "<img src='smiley1.gif'>"
  10.    smileyGraphics(2) = "<img src='smiley2.gif'>"
  11.    '...
  12.  
  13.    dim fixedText
  14.    for x = 0 to 9
  15.       fixedText = replace(chatText, smileys(x), smileyGraphics(x))
  16.    next
  17.  
  18.    response.write fixed text
  19. end function
  20.  
  21. '...
  22.  
  23. smilify(chatmsg("TBLmessage"))
  24.  
Of course you can get much fancier by keeping your smileys in a db or something, but this should work for your app. Let me know if this helps.

Jared
Newbie
 
Join Date: Jul 2009
Posts: 8
#4: Jul 21 '09

re: Smilie filter


i could not get the script to work. i got the firsrt one to work as such. i try again and i post some more
Newbie
 
Join Date: Jul 2009
Posts: 8
#5: Jul 21 '09

re: Smilie filter


wait both them did not work. i got this error

" microsoft VBScript runtime error '800a005e'
Invalid use of Null: 'Replace@
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#6: Jul 23 '09

re: Smilie filter


Quote:

Originally Posted by petvampire View Post

wait both them did not work. i got this error

" microsoft VBScript runtime error '800a005e'
Invalid use of Null: 'Replace@

post that exact line of code. It sounds like you have a typo there.

Jared
Newbie
 
Join Date: Jul 2009
Posts: 8
#7: Jul 25 '09

re: Smilie filter


Expand|Select|Wrap|Line Numbers
  1.  <%=(chatmsg.Fields.Item("TBLusername").Value)%></span>
  2.       <span class="style7"><font color="#9900FF">
  3.       <%function smilify(chatText) 
  4.    dim smileys(10) 
  5.    dim smileyGraphics(10) 
  6.    smileys(0) = ":)" 
  7.    smileys(1) = ":S" 
  8.    smileys(2) = ";)" 
  9.    '... 
  10.    smileyGraphics(0) = "<img src='smiley0.gif'>" 
  11.    smileyGraphics(1) = "<img src='smiley1.gif'>" 
  12.    smileyGraphics(2) = "<img src='smiley2.gif'>" 
  13.    '... 
  14.  
  15.    dim fixedText 
  16.    for x = 0 to 9 
  17.       fixedText = replace(chatText, smileys(x), smileyGraphics(x)) 
  18.    next 
  19.  
  20.    response.write fixed text 
  21. end function 
  22.  
  23. '... 
  24. %>
  25. <% smilify(chatmsg("TBLmessage")) %></font> 
  26.  
  27.  
thats how i tried to implement it. not sure if i done it correctly as my .asp know how is still limited.
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#8: Jul 27 '09

re: Smilie filter


Quote:

Originally Posted by petvampire View Post

Expand|Select|Wrap|Line Numbers
  1.  <%=(chatmsg.Fields.Item("TBLusername").Value)%></span>
  2.       <span class="style7"><font color="#9900FF">
  3.       <%function smilify(chatText) 
  4.    dim smileys(10) 
  5.    dim smileyGraphics(10) 
  6.    smileys(0) = ":)" 
  7.    smileys(1) = ":S" 
  8.    smileys(2) = ";)" 
  9.    '... 
  10.    smileyGraphics(0) = "<img src='smiley0.gif'>" 
  11.    smileyGraphics(1) = "<img src='smiley1.gif'>" 
  12.    smileyGraphics(2) = "<img src='smiley2.gif'>" 
  13.    '... 
  14.  
  15.    dim fixedText 
  16.    for x = 0 to 9 
  17.       fixedText = replace(chatText, smileys(x), smileyGraphics(x)) 
  18.    next 
  19.  
  20.    response.write fixed text 
  21. end function 
  22.  
  23. '... 
  24. %>
  25. <% smilify(chatmsg("TBLmessage")) %></font> 
  26.  
  27.  
thats how i tried to implement it. not sure if i done it correctly as my .asp know how is still limited.

sorry if I wasn't clear, my ellipses (...) were supposed to be other lines you wrote if you wanted to replace more smilies with graphics. the code I wrote that you copied only replaces 3. also the code that says "for x = 0 to 9", those are supposed to be the nu8mbers for which you have smilies listed in the lines where I put ellipses. for the code you copied from my post, it only makes sense to say "for x = 0 to 2" since there are only smilies 0, 1, and 2 defined. Does this make sense? The error probably just means that it tried to find a definition for smilie(3) and you never defined it.

Let me know if this makes sense, I can probably explain it a little clearer.

Jared
Newbie
 
Join Date: Jul 2009
Posts: 8
#9: Aug 5 '09

re: Smilie filter


Microsoft VBScript compilation error '800a03ea'

Syntax error

/apps/chat/room/thelocal/chat-display-push.asp, line 134

function smilify(chatText)
^


thats the error im now getting
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#10: Aug 7 '09

re: Smilie filter


Ah, I looked back over your code, and I actually gave you the code as a subroutine even though I said to use "function ... end function". Change the word "function" both at the beginning and end of that block of code to "sub" and see if it works.

Jared
Newbie
 
Join Date: Jul 2009
Posts: 8
#11: Aug 15 '09

re: Smilie filter


still no joy. this is the error now

Microsoft VBScript compilation error '800a03ea'

Syntax error

/apps/chat/room/thelocal/chat-display-push.asp, line 144

sub smilify(chatText)
^
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#12: Aug 18 '09

re: Smilie filter


hmm. It works for me. here is the complete code I tested, and I got no error.
Expand|Select|Wrap|Line Numbers
  1. <%
  2.  sub smilify(chatText) 
  3.     dim smileys(10) 
  4.     dim smileyGraphics(10) 
  5.     smileys(0) = ":)" 
  6.     smileys(1) = ":S" 
  7.     smileys(2) = ";)" 
  8.     '... 
  9.     smileyGraphics(0) = "<img src='smiley0.gif'>" 
  10.     smileyGraphics(1) = "<img src='smiley1.gif'>" 
  11.     smileyGraphics(2) = "<img src='smiley2.gif'>" 
  12.     '... 
  13.  
  14.     dim fixedText 
  15.     fixedText = chatText
  16.     for x = 0 to 9 
  17.        fixedText = replace(fixedText, smileys(x), smileyGraphics(x)) 
  18.        response.write "<!--  -->" & vbNewLine
  19.     next 
  20.  
  21.     response.write fixedText & "<br>" & vbnewline
  22.  end sub 
  23.  
  24. %>
  25. <html>
  26. <head><title></title>
  27. </head>
  28. <body>
  29. <%
  30. dim chatMsg
  31. chatmsg="hi there LOL :)"
  32.  
  33. smilify(chatMsg)
  34.  
  35. 'response.write chatMsg & "<br>" & vbNewLine
  36. response.write "hello world"%>
  37. </body>
  38. </html>
  39.  
Reply

Tags
chat, filter, smilie filter