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

Syntax error in response.write statement

Status
Not open for further replies.

kosmokramer

Programmer
Sep 8, 2002
73
0
0
US
I am trying to test the variables being sent to a sub, so I am only getting it to print out the variables once they are sent to the sub. The problem is that I am getting a type mismatch error in the string I am writing out that calls the sub

Here's the string:
Code:
Response.Write ("</td><td>" & openConnection("'" & Session.Contents(i) & "'",theQuant) & "</td><td><a href='procPage.asp?movieName=" & Session.Contents(i) & "' class='descriptionBlock'><font size=-1>Delete Movie?</font></a></td></tr>")

and here's the sub:
Code:
Sub openConnection(theMovie, movieQuantity)
	Response.Write ("theMovie: " & theMovie & " quantity: " & movieQuantity)
End Sub

Any ideas? By the way, Session.Contents(i) is the name of a movie and theQuant is the quantity of movies. Also, the table tags you see are right...I mean to have a </td> tag at the beginning of this string. Thanks ahead of time!
 
Your sub isn't equal to anything, but you're asking your Response.Write to append it to other string stuff. Your sub does write something, but that doesn't mean it is something.

In your sub put:
Code:
    openConnection = "theMovie: " & theMovie & " quantity: " & movieQuantity
so that it returns the string rather than trying to write it.
 
Humm..I was wondering about that. Thanks for the help, but I am still getting the same error:
Code:
Microsoft VBScript runtime error '800a000d' 

Type mismatch: 'openConnection'
I even tried it with hard coded variables:

Code:
temp = "Bourne Identity"
temp2 = 5

Response.Write ("</td><td>" & openConnection(temp,temp2) & "</td><td><a href='procPage.asp?movieName=" & Session.Contents(i) & "' class='descriptionBlock'><font size=-1>Delete Movie?</font></a></td></tr>")
 
i don't think you can call the method openConnection in the string, e.g. Response.Write is generating a string of text. Try creating a varible set the value of openConnection results and then placing it in the Response.Write criteria.

Regards,


Lewis Harvey
lewis@lharvey.com
 
Woo hoo! Got it working! Thanks winston. Alright, now I am having another problem:
Code:
Microsoft VBScript runtime error '800a01a8' 

Object required: 'objRS'

I think this problem has to do with objRS being closed out, but not being redefined. I don't see why this is a problem...

Here are my subs:
Code:
Sub openConnection(theMovie, movieQuantity)
	Dim objConn, objRS, strConn, strSQL
	Set objConn = Server.CreateObject("ADODB.Connection")
	strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _
	& "Data Source=Blah blah...the data source stuff.."
	objConn.ConnectionString = strConn
	objConn.Open
	Set objRS=Server.CreateObject("ADODB.Recordset")
	strSQL = "Select cost from Movies where movieTitle='" & theMovie & "'"
	objRS.Open strSQL, objConn
	Response.Write("$" & objRS("cost") * movieQuantity)
	closeConnection()
End Sub

Sub closeConnection()
	objRS.Close
	Set objRS=nothing
	objConn.Close
	Set objConn=nothing
End Sub

What I am doing is looping through the Session contents and calling openConnection each time through

Code:
openConnection Session.Contents(i), theQuant

why would it give me an error if I call the close connection each time. I would think it would recreate the variables the next time openConnection is called...
 
Which line is the error hitting on?

-----------------------------------------------------------------------------------------------------
&quot;If you can't explain something to a six-year-old, you really don't understand it yourself.&quot;
-- Albert Einstein
 
Hey. Thanks Chopstik. Though all you did was ask a question, it made me look at which line again, and lo and behold, I found the error. What happened was that the first line of the closeConnection() sub was throwing the error. I suppose because the objRS object was not being passed to it. So, when it tried to do objRS.close, it did not know what objRS was. So, all I did was to put the closeConnection code into the openConnection sub. By the way, how would you pass the object? I always get a little hazy when it comes to passing objects as opposed to regular variables.
 
I believe what occurred was because you were creating your objRS in the openConnection sub, it was only recognised within that sub. If you wanted it recognised external to that sub, you would have to declare it external to any single sub. Hope that makes sense.

-----------------------------------------------------------------------------------------------------
&quot;If you can't explain something to a six-year-old, you really don't understand it yourself.&quot;
-- Albert Einstein
 
Yeah. I was not thinking of that when I created the subs. Usually I just declare a lot of global variables and never have to worry about that since I don't usually work with subs.

So, back to my question, how would you pass the objRS object?

Is it something like:
Code:
closeConnection(ByRef objRS)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top