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!

Escaping Quotes 1

Status
Not open for further replies.

MatthewP

Programmer
Jan 16, 2001
176
GB
Hi - I'm trying to drop a variable in a Request.Form query like so:

If Request.Form("item" + myVar + "") Then..

Obviously the above doesn't work. I've tried about eight different configurations of the above, like Request.Form(myVar) etc, and each time I get this error :- Type mismatch: '[string: ""]'

Surely there is a way to do this?

Thanks,

Matt.
 
Try this
If Request.Form("item" & myVar) Then..

if that dosent work try this

myVar="item" & myvar

If Request.Form(myVar) Then..

Mark
 
Thanks Mark, but it still doesn't work. I've tried with & and +, both joining the string outside the ResponseWrite statement and within. I cannot seem to drop a variable into it at all. I've tried the statement with an absolute name, and it works fine, so there's nothing else in the code that's causing any problems.

Matt.

 
Matt,

It's hard to know what to say. Millions of VB and VBScript programers in the world perform string concatination every day using syntax that Mark describes. It really does work. I would tend to believe that there is an error somewhere in your code.

"But, that's just my opinion... I could be wrong".
-pete
 
If I understood you right, you have a form with few input fields named "item1", "item2" and so on...
Here's a piece of simple code, that'll may be help you to figure out a way to make your code work:

html page
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>
</HEAD>
<BODY>

<form name=&quot;form1&quot; action=&quot;Concat_var.asp&quot; method=&quot;post&quot;>
<input type=&quot;text&quot; name=&quot;item1&quot;><br>
<input type=&quot;text&quot; name=&quot;item2&quot;><br>
<input type=&quot;text&quot; name=&quot;item3&quot;><br>
<input type=&quot;text&quot; name=&quot;item4&quot;>
<input type=&quot;submit&quot;>
</form>

</BODY>
</HTML>

Concat_var.asp
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
</HEAD>
<BODY>

<%
dim ind
for ind = 1 to 4
if len(Request.Form(&quot;item&quot; &amp; ind))<> 0 then
Response.Write &quot;Item&quot; &amp; ind
end if
next

%>

Try it out.
 
Thanks everyone - that last example works great. I think the problem is coming in as the number that follows the item is generated from a database query, and is stored as RS(&quot;stocknum&quot;)

So, the entire string is :

Do While NOT RS.EOF

myVar = RS(&quot;stocknum&quot;)
If Request.Form(&quot;item&quot; &amp; myVar) Then

...

End If
RS.MoveNext
Loop

Obviously I can't do Request.Form(&quot;item&quot; &amp; RS(&quot;stocknum&quot;)) as the quotes interfere with each other, but even with RS(&quot;stocknum&quot;) stored in myVar as in my example above, I still get the string error :

Microsoft VBScript runtime error '800a000d'
Type mismatch: '[string: &quot;&quot;]'
readdata.asp line 62
(the line with the Request.Form query..)

Just can't seem to get rid of the darn quotes....!

Thanks,
Matt.


 
Try this
If Request.Form(&quot;item&quot; &amp; str(myVar)) Then..

or this

myVar2=&quot;item&quot; &amp; STR(myvar)

If Request.Form(myVar2) Then..

Mark
 
Try to change If...Then statement to the way it looks in the my reply:
If len(request.form(&quot;item&quot;)&amp; RS(&quot;stocknum&quot;)) <> 0 Then ...

I think, that this is the condition [red]If request.form(&quot;item&quot;)[/red] that gives you an error.
 
Thanks everyone. I've finally got it working by a combination of everything from above(!), and setting default values of '0' in all the form fields on the form page. Very strange. Maybe with a bit more experience of ASP I'll work out where it went wrong one day, but at least it works.

Thanks Again!
Matt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top