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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This is not working... 2

Status
Not open for further replies.

JrClown

Technical User
Oct 18, 2000
393
US
Would someone please help me in troubleshooting this code please?

This code is supposed to ignore ' (Apostrophes) marks around comments typed on my comments field in an ASP form.

Here's the error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression ''this is only a test I'm typing', 'jr_clown@yahoo.com')'.


function changed_tick(fieldstring)
holdstring = ""
for x = 1 to len(fieldstring)
holdchar = mid(fieldstring,x,1)
if holdchar = chr(39) then
holdstring = holdstring & "' " & chr
43) & " char(39) " & chr(43) & "'"
elseif holdchar = chr(34) then
holdstring = holdstring & "' " & chr(43) & " char(34) " & chr(43) & "'"
else
holdstring = holdstring & holdchar
end if
next

changed_tick = "'" & holdstring & "%'"
end function
QUOTE OF THE DAY
The only ideas that will work for you are the ones you put to work.
<%
Jr Clown
:eek:)
%>
 
Explain your final goal a bit please because this is the result I'm getting from your function which I do not think is what you're looking for:

&quot;Hello&quot; 'World' shows up as:

'' + char(34) +'Hello' + char(34) +' ' + char(39) +'World' + char(39) +'%'

I have a strange feeling you did not want the char(34) and 39's to show up as actual values in your final string, in which case, you'd have to remove the &quot;'s that you have around it.

Also, there's a much easier way to accomplish this if I'm understanding you correctly.

Best thing is tell me how this phrase should look when it's all done:

&quot;Hello&quot; 'World'

I'll be looking for a response. Ed (RoadRacer) Holguin

&quot;I Hate Computers!&quot;
 
Thanks for you input RoadRacer,
I don't know how &quot;Hello World&quot; showed up, I don't see it in my code. But anyway, here's what I need:


I have a comments field and when my users type &quot;I'm going to Floriday on Vacation
the page give the error above, But if my users type &quot; I am going to Florida without the &quot;apostrophe&quot;, it works just fine.

I need to tweek the code so it accepts Quotes\Ticks\Exclamation points etc.
Any ideas???
X-)
Does this make sense?

QUOTE OF THE DAY
The only ideas that will work for you are the ones you put to work.
<%
Jr Clown
:eek:)
%>
 
Yep, makes perfect sense.

Hello World is the value I passed to your function to see the results. hehehe

Anyhow, I'm not understanding where you are using this output string in. Is in going to an SQL statement and you need the quotes/ticks etc. to be passed as values?

Basically, let's use the phrase you used as an example

I'm going to Florida

How do you want the actual output to look? Do you want the apostrophe ommitted so it looks like this?

Im going to Florida

Or do you just need to know how to represent an apostrophe correctly in an SQL statement?
Ed (RoadRacer) Holguin

&quot;I Hate Computers!&quot;
 
Yes Mr. Computer Hater :), I need to represent an apostrophe\ ! \ &quot;&quot; correctly in an SQL statement
QUOTE OF THE DAY
The only ideas that will work for you are the ones you put to work.
<%
Jr Clown
:eek:)
%>
 
Ah, then all you have to do is overload the apostrophe and the double quotes in the SQL statement. Your FLORIDA example should be passed like this:

SELECT * FROM _____ WHERE _____ LIKE 'I''m in Florida%';

I hope this is what you're looking for.

As far as the exclamation point, I've never run into a problem, I just pass that as is. Ed (RoadRacer) Holguin

&quot;I Hate Computers!&quot;
 
Excuse my inexperience in VBScript, but I don't understand how this would apply to a text box variable

These are the fields I'm populating in my access table
&quot;'&quot;& request.form(&quot;thrudate&quot;)& &quot;', &quot; &_
&quot;'&quot;& request.form(&quot;comments&quot;)& &quot;', &quot; &_
&quot;'&quot;& session(&quot;email&quot;)& &quot;', &quot; &_

Should I not enclose my &quot;comments&quot; field in double-quotes? QUOTE OF THE DAY
The only ideas that will work for you are the ones you put to work.
<%
Jr Clown
:eek:)
%>
 
AHA! I think I finally understand your situation. You're passing your comments field and if it has a single quote it messes up, right? Ok, what you have to do is still overload it ... Easiest way to guarantee a replacement of a certain string is using the Replace command. Try plugging this in and let me know how it works, I'm going to modify your code just a bit.

&quot;'&quot;& request.form(&quot;thrudate&quot;)& &quot;', &quot; &_
&quot;'&quot;& Replace(Request.Form(&quot;comments&quot;), &quot;'&quot;, &quot;''&quot;)& &quot;', &quot; &_
&quot;'&quot;& session(&quot;email&quot;)& &quot;', &quot; &_

The Replace function will find every ' that you have and replace it with 2 's. If that's the only character you need to replace, that will work fine. Should you need to do it to others, here's the layout of the values to pass to the Replace function.

Replace([original string], [value to be replaced], [value to replace it with])

Example, let's say Hello World is our value.

Replace(&quot;Hello World&quot;, &quot;l&quot;, &quot;L&quot;)

That will result in this ...

HeLLo WorLd

I hope this helps, if not, I'm still monitoring. =)

And yeah .. I do hate computers. hehe Ed (RoadRacer) Holguin

&quot;I Hate Computers!&quot;
 
Sorry, that font makes code very hard to read ... this is probably easier on the eyes.

Code:
&quot;'&quot;& request.form(&quot;thrudate&quot;)& &quot;', &quot; &_ 
&quot;'&quot;& Replace(Request.Form(&quot;comments&quot;), &quot;'&quot;, &quot;''&quot;)& &quot;', &quot; &_ 
&quot;'&quot;& session(&quot;email&quot;)& &quot;', &quot; &_
Ed (RoadRacer) Holguin

&quot;I Hate Computers!&quot;
 
RoadRacer, it did not work at all. I kept getting the my original problem.

I have now instructed all users to simply when typing apostrophes to just type two in a row (i.e. I''am going to Florida) that fixes the problem just fine. I appreciate your help and time on this. QUOTE OF THE DAY
The only ideas that will work for you are the ones you put to work.
<%
Jr Clown
:eek:)
%>
 
I have to agree with roadRacer on this one. the Replace() statement should do the trick (which is exactly what you would instruct your users, but now code takes care of it) Yours,

Rob.
 
I use a function that takes the entire form collection and stuffs it into another collection (a Dictionary object) but, as it moves the contents from the Request.Form collection over to the Dictionary object, it replaces all single apostrophes with double apostrophes.

<%
Function RemoveCharacters()
dim frm,item
Set frm = Server.CreateObject(&quot;Scripting.Dictionary&quot;)
frm.CompareMode=1
For each Item in Request.Form
frm.Add Cstr(Item), Replace(Request.Form(Item),&quot;'&quot;,&quot;''&quot;)
Next
Set RemoveCharacters = frm
End Function
%>

Calling and using this function is a breeze:

<%
dim myform
Set myform = RemoveCharacters()

myform(&quot;formfieldname&quot;) ' refer to a specific form field
%>

Hope this helps
 
thanks you very much for you assistance guys
here's what I'm getting now SeAL
error[/u]

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method

/levacation/verify2.asp, line 19

<%
dim myform
Set myform = RemoveCharacters()
Line 19 = myform(&quot;comments&quot;)
%>

Code suggested:
Should I make changes to the code you gave me?
Function RemoveCharacters()
dim frm,item
Set frm = Server.CreateObject(&quot;Scripting.Dictionary&quot;)
frm.CompareMode=1
For each Item in Request.Form
frm.Add Cstr(Item), Replace(Request.Form(Item),&quot;'&quot;,&quot;''&quot;)
Next
Set RemoveCharacters = frm
End Function
%>



QUOTE OF THE DAY
The only ideas that will work for you are the ones you put to work.
<%
Jr Clown
:eek:)
%>
 
it works perfectly for me, I can't find any mistakes in my sample :-/
 
I have made more changes and this is what I'm getting now
changes:
Function RemoveCharacters()
dim frm,item
Set frm = Server.CreateObject(&quot;Scripting.Dictionary&quot;)
frm.CompareMode=1
For each Item in Request.Form
frm.Add Cstr(comments), Replace(Request.Form(comments),&quot;'&quot;,&quot;''&quot;)
Next
Set RemoveCharacters = frm
End Function
%>

<%
dim myform
Set myform = RemoveCharacters()
myform(&quot;comments&quot;)
%>
NEW ERROR
Request object error 'ASP 0102 : 80004005'

Expecting string input

/levacation/verify2.asp,

The function expects a string as input.


QUOTE OF THE DAY
The only ideas that will work for you are the ones you put to work.
<%
Jr Clown
:eek:)
%>
 
That's not gonna work Jr.

You have to leave ITEM in there where you replaced it with COMMENTS. You never defined comments so that's why you're getting this second error.

Other than that I can't see what else could be wrong with the function, I haven't run it but see no reason why it wouldn't work.

Also, you have to do something with the final myform(&quot;____&quot;) line in this code:

<%
dim myform
Set myform = RemoveCharacters()
Line 19 = myform(&quot;comments&quot;)
%>

Your line 19 up above is doing nothing.

Maybe Response.Write it or something. Just dropping it blankly into the code like that doing nothing will cause an error. Ed (RoadRacer) Holguin

&quot;I Hate Computers!&quot;
 
Sorry guys, I don't quite understand what should be typed within my ( ) below

Function RemoveCharacters()
dim frm,item
Set frm = Server.CreateObject(&quot;Scripting.Dictionary&quot;)
frm.CompareMode=1
For each Item in Request.Form
frm.Add Cstr(item), Replace(Request.Form(item),&quot;'&quot;,&quot;''&quot;)
Next
Set RemoveCharacters = frm
End Function
%>

<%
dim myform
Set myform = RemoveCharacters(&quot;'&quot;)
myform(&quot;''&quot;)

I'm trying to learn as we go, and I have a headache. X-)
QUOTE OF THE DAY
The only ideas that will work for you are the ones you put to work.


<%
Jr Clown
%>
 
Oh yeah, and this is the error I got this time

Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment: 'RemoveCharacters'

/levacation/verify2.asp, line 19
QUOTE OF THE DAY
The only ideas that will work for you are the ones you put to work.


<%
Jr Clown
%>
 
Hehe, no problem man, none of us know everything, if we did, this forum wouldn't exist. =)

Try this (of course, assumming that COMMENTS is the name of one of the fields in your form.) This should output the comment field as you need it, with overloaded single ticks.

Code:
dim myform
Set myform = RemoveCharacters()
Response.Write myform(&quot;comments&quot;)
Ed (RoadRacer) Holguin

&quot;I Hate Computers!&quot;
 
BTW, a little note, if you notice on the FUNCTION line of the code that SeAL provided, he has the function set as:

Function RemoveCharacters()

Since he is not asking for any parameters (you can tell because the parentheses are empty) then passing a parameter will cause an error. When you called the function and put ' in there, you attempted to provide a value and the function said ... NO DICE!

Just a little insight how parameters work. =) Ed (RoadRacer) Holguin

&quot;I Hate Computers!&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top