473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.
Jul 10 '09 #1
11 2355
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.
Jul 10 '09 #2
jhardman
3,406 Expert 2GB
@petvampire
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
Jul 13 '09 #3
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
Jul 21 '09 #4
wait both them did not work. i got this error

" microsoft VBScript runtime error '800a005e'
Invalid use of Null: 'Replace@
Jul 21 '09 #5
jhardman
3,406 Expert 2GB
@petvampire
post that exact line of code. It sounds like you have a typo there.

Jared
Jul 23 '09 #6
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.
Jul 25 '09 #7
jhardman
3,406 Expert 2GB
@petvampire
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
Jul 26 '09 #8
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
Aug 5 '09 #9
jhardman
3,406 Expert 2GB
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
Aug 7 '09 #10
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)
^
Aug 15 '09 #11
jhardman
3,406 Expert 2GB
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.  
Aug 17 '09 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Robin Cull | last post by:
Imagine I have a dict looking something like this: myDict = {"key 1": , "key 2": , "key 3": , "key 4": } That is, a set of keys which have a variable length list of associated values after...
1
by: Robert Neville | last post by:
I would like to add filter functionality to my database whether through the Main form or the subform. This question may be rudimentary, yet I have not less experience with filtering data outside...
0
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the...
3
by: Richard | last post by:
Hi, I have a form based on a table. When I filter the form I want to run a report based on the same table with the same filter as the form. No problem until I want to filter a combo box where...
8
by: dick | last post by:
I am just trying to print/report the results of a "filter by selection" which is done by right-clicking a form, filling in values, and "applying the filter." I have searched the newsgroups, and...
2
by: Salad | last post by:
I have a log file with a list of records. The log file can be unfiltered or filtered. I have a command button to call a data entry form from the log. At first I was only going to present the...
2
by: Mike Sweetman | last post by:
I have a form Form1 which when the Advanced Filter/Sort is used creates a form(maybe) with a title 'Form1Filter1 : Filter'. When I apply the filter to Form1 it is applied, but the value of...
8
by: marcus.kwok | last post by:
I am having a weird problem and I have can't figure out why it is happening. I create an OpenFileDialog and set a filename filter. When the dialog first opens, the filter works correctly, and...
15
by: Briansmi1116 | last post by:
I created two buttons, that filter my form, They filter in different Fields, and if one is filtered, and the other is not there is a certain amount of record, if they are both pushed, then there is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.