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

Left() is creating a Invalid procedure call WHY?? 1

Status
Not open for further replies.

gwigton

Programmer
Jul 23, 2002
52
US
There is probably a better way to do this and with the deadline for this project sneeking up on me, I am open to anything. I am performing a query based off a passed variable value. The variable is seeing the value as the value plus quotes. I need to strip the quote marks before I can use the value in the query. To do this I have the following lines of code.

<%strTitle=Request.QueryString(Trim(strTitle))
strTitle=left(strTitle,len(Trim(strtitle))-1)
strTitle=right(strTitle,len(Trim(strtitle))-1)%>

As you can see I am reqerying the variable and then pulling off the quotes on each end. It worked perfectly Tuesday evening when I left, but on Wedness day morning I suddenly started getting an error that says:

Error Type:
Microsoft VBScript runtime (0x800A0005)
Invalid procedure call or argument: 'left'

If I comment these two lines out the code works fine (except for the correct query results which ends up returning nothing since the variable has quotes included)

Any ideas???
 
Cant you simply use Replace function something like this:

<%
strTitle=Request.QueryString(Trim(strTitle))
strTitle= Replace(strTitle,""","")- Replace double quotes with empty space
or if it is a single quote then

strTitle= Replace(strTitle,"'","")

then again
strTitle= Trim(strTitle)


Hope this helps.


-VJ

 
Hello qwiqton,

If you trim the len, trim the left and right first argument as well.

But, trim is not warranted here. What is the request return a string of blank and without quotes. Len(trim()) will evaluate to zero, hence, the error. Just a guess.

regards - tsuji
 
Thanks for the tip amorous. tsuji this is starting to make sense now; at least a little. I have tested the value of strTitle and it is returning nothing. But I am now wondering why it is not getting the value when the other day it was. This is the code for passing the value:

<a href='columbus.asp?strTitle="<%Response.Write(rs.Fields.Item("title").Value)%>"'>
<%Response.Write(rs.Fields.Item("title").Value)%></a>

Esentually what the page is doing is when it is first loaded it displays several links (which are actually titles of courses) then when the user clicks the link it reloads the same page but displays a discription of that course in the center of the page and the course title links. See any problem with the line of code I am using to put the title into the strTitle variable?
 
gwigton,

Try this.
Code:
<a href="columbus.asp?strTitle=<%=Response.Write(rs.Fields.Item("title").Value)%>">
     <%=Response.Write(rs.Fields.Item("title").Value)%></a>
- tsuji
 
is it not <%=(rs.Fields.....)%> equivalent to <%Response.Write(rs.Fields.....)%>


-VJ
 
Hello amorous,

Yes, I prefer yours. Sorry, my mistake! gwigton, try take away response.write.

- tsuji
 
Ok, first, to answer the original question, the Left function is failing because of the 0 length string, not necessarally because your asking for 0 characters, but because no matter how many characters you ask it for, Left will give you an error on a null string.

Second, I'm not entirely sure what your doing on the Request.Form line, it doesn't make sense.
Code:
'your code
strTitle=Request.QueryString(Trim(strTitle)) 

'proper method to pull something out of Request collection
strTitle=Request.QueryString("strTitle")

The only way that first line will work is if the value for your strTitle variable is initially set to the string "strTitle". Request.QueryString is a collection and wants either a a numeric index or a string key. The only reason i could see it working the way it is is because the variable has not been set (defaults to 0), gets converted to a string for the trim, then gets converted back to a number and is treated as a numeric index. Not a good plan and wasteful.

Third, your variable in the a href does not need double quotes around it. What is happening is those quotes are being read as part of the value rather than surrounding the value. As was mentioned above (though it may have been misleading due to the Response.Write vs = portion) just leave the quotes off in the value part of your querystring and then you won't need to strip them on the next page. If your concerned about characters that won't translate correctly into a URL, look into using the URLEncode function before writing the value to your anchor tag.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Well after you mentioned it, I was sure that would work, but I end up getting the following error:

Error Type:
Microsoft VBScript runtime (0x800A01C2)
Wrong number of arguments or invalid property assignment: 'Value'

and my code looks like:

<a href='columbus.asp?strTitle=<%rs.Fields.Item("title").Value%>'>
<%Response.Write(rs.Fields.Item("title").Value)%></a>

I also tried

a href='columbus.asp?strTitle=<%rs.Fields("title").Value%>'>
<%Response.Write(rs.Fields.Item("title").Value)%></a>



 
The problem there is that your not doing anything with the first call to the value, no = or Response.Write:
Code:
<a href='columbus.asp?strTitle=<%[highlight]=[/highlight]rs.Fields.Item("title").Value%>'>
     <%Response.Write(rs.Fields.Item("title").Value)%></a>

'or

<a href='columbus.asp?strTitle=<%[highlight]Response.Write[/highlight] rs.Fields.Item("title").Value%>'>
     <%Response.Write(rs.Fields.Item("title").Value)%></a>

<%=variable%> is merely a shortcut for <% Response.Write variable%>

In this case since you weren't doing aything with the value once you accessed it, the server was confused. It was expecting you to either retrieve the value (either into a variable or as output with Response.Write) or assign it a new value (.Value is read/write), but instead you weren't doingnothing with it :) Probably just an accidental deletion of the = sign though.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Ok everyone after playing with it a little more I found the problem before reading Tarwn's post. and he is exactally right. The double quotes in front of the line that read:

<a href="columbus.asp?strTitle='<%=Response.Write(rs.Fields.Item("title").Value)%>'">
<%=Response.Write(rs.Fields.Item("title").Value)%></a>

Wasn't truely the problem, but it was making me go through the extra step that was causing the problem. Like Tarwn said the exact problem was the following line:

strTitle=Request.QueryString(Trim(strTitle))

It should have been
<%strTitle=Request.QueryString("strTitle")
strTitle = Replace(strTitle,"""", "")%>

the second line would accomidate for the quote problem. Once again Tek-Tips saves the day!

Thanks to everyone for their quick responses and suggestions. Tarwn the star has got to go to you man!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top