General discussion


Invalid procedure call or argument: left

By munrrob ·
I am using an ASP page running on IIS6 using VBScript as the programming language. I am trying to display the first part of body text from a freetext field as part of a news headline section on the home page. The code I have is:

if not isnull(objRSNews("tblNewsTitle")) or objRSNews("tblNewsTitle")<>"" then
response.Write "<H6>" & objRSNews("tblNewsTitle") & "</H6>"
strFirstParagraph = left(objRSNews("tblNewsBody"), instr(objRSNews("tblNewsBody"),Chr(13))-1)
response.Write "<p>" & strFirstParagraph & "</p>"
end if
I am getting the error message in the title when trying to rn this. Can anyone give me an idea why?
I have set the client language to VBScript in IIS and given full permissions to the application.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by MadestroITSolutions In reply to Invalid procedure call or ...

Dear user,

The reason why this is difficult to troubleshoot is because you are not using variables to make your code more clear. Instead of repeating [objRSNews("tblNewsBody")] all over, how about assigning it to a variable?... say for example "nBody"... Same holds true for the title, and you should also assign the [instr] function result to another variable. That will help you troubleshoot problems like this more efficiently, since you will be able to get down to the very instruction or function call that produces an error. See the following code:

Dim nTitle, nBody, BreakPos
nTitle = objRSNews("tblNewsTitle")
nBody = objRSNews("tblNewsBody")
if not isnull(nTitle) or nTitle <>"" then
response.Write "<H6>" & nTitle & "</H6>"
BreakPos = instr( nBody, Chr(13) ) - 1
strFirstParagraph = left( nBody, BreakPos)
response.Write "<p>" & strFirstParagraph & "</p>"
end if

That being said, if you look at the code above, it quickly becomes evident that nBody (News Body) may NOT contain a break line character (chr(13)). If that is the case, the function will return 0 as a result and you will end up with a BreakPos = -1. That in turn will cause an error on the function when you attempt to get "-1" characters.

I hope that helps.

Good Luck!

Collapse -

by munrrob In reply to

Thank you for this, much appreciated.

Collapse -

by munrrob In reply to Invalid procedure call or ...

This question was closed by the author

Related Discussions

Related Forums