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

Cannot use parentheses when calling a Sub

Status
Not open for further replies.

aspvbnetnerd

Programmer
May 16, 2006
278
SE
I get the error message "Cannot use parentheses when calling a Sub"
I only get this message when using "Array(valu)" in my sql

My code
Code:
<!--#include file="databaseconnection.asp" -->
<%
Dim Connection, Recordset, frmInformation, frmText

frmText = Request.Form("text")
frmPid	= Request.Form("pid")
Open()
[b]Value("SELECT TOP 1 * FROM tblItemInfo where pid={0}", Array(frmpid))[/b]
Close() 

Response.Write(frmPid)
%>

link to my databaseconnection code


What shall I do to fix this?


George
 
I tried doing Call Value("SELECT TOP 1 * FROM tblItemInfo where pid={0}", Array(frmpid)) I got this message

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

George
 
That code in your link is horrid. I've never seen such a bad use of reserved words before in my career.

You're passing to many args to the function.

[sub]____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done[/sub]
 
I didn't work
I got the same error when I tried both method

frmpid = Value("SELECT TOP 1 * FROM tblItemInfo where pid={0}")
Call Value("SELECT TOP 1 * FROM tblItemInfo where pid={0}")

the message is in swedish
Microsoft JET Database Engine (0x80040E14)
Felaktig GUID. i frågeuttrycket 'pid={0}'.
/felipe/lib/include/databaseconnection.asp, line 21


onpnt, thanks for pointing that out.
I will change it right after this is solved.

George
 
I tried this frmpid = Value("SELECT TOP 1 * FROM tblItemInfo where pid=0") and it gave me this error.

Microsoft JET Database Engine (0x80040E10)
No values given for one or more required parameters
felipe/lib/include/databaseconnection.asp, line 21
 
Thanks for the help everyone.
Now it works

I talk to a friend of my and he said was I doing it wrong.
Code:
Call GetValue("SELECT TOP 1 * FROM tblItemInfo where pid={0}", Array(frmpid))

Code:
	Public Function GetValue(strSQL, arrParameters)
		CheckForOpenConnection
		strSQL=GetSQL(strSQL, arrParameters)
		
		On Error Resume Next
		Dim Recordset
		Set Recordset=Server.CreateObject("ADODB.Recordset")
		Recordset.CursorLocation=adUseClient
		Recordset.Open strSQL, objConnection, adOpenStatic, adLockReadOnly
		ReportError Err, strSQL
		GetValue=Recordset.Fields(0).Value
		Recordset.Close
		Set Recordset=Nothing
		On Error Goto 0
	End Function	
	
	Public Function GetSQL(strSQL, arrParameters)
		If IsArray(arrParameters)=False Then
			GetSQL=strSQL
			Exit Function
		End If
		
		Dim lngParamCount, strSQLResult, varValue
		strSQLResult=strSQL
		For lngParamCount=LBound(arrParameters) To UBound(arrParameters)
			varValue=arrParameters(lngParamCount)
			Select Case VarType(varValue)
				Case vbEmpty, vbNull : varValue="null"
				Case vbString, vbDate : varValue="'" & Escape(varValue) & "'"
				Case vbObject : varValue="'[object]'"
				Case vbError : varValue="'" & Escape("[error: " & varValue.Description & "]") & "'"
				Case vbInteger, vbSingle, vbDouble, vbCurrency, vbBoolean, vbDecimal, vbLong
					' These values needs no changes.
				Case Else
					varValue="[unknown vartype (" & VarType(varValue) & " [" & TypeName(varValue) & "])]"
			End Select
			strSQLResult=Replace(strSQLResult, "{" & lngParamCount & "}", varValue)
		Next
		GetSQL=strSQLResult
	End Function	
	
	Private Sub CheckForOpenConnection()
		If Connection.State<>adStateOpen Then
			On Error Resume Next
			Err.Raise -1, "DatabaseConnection", "Database connection is closed."
			ReportError Err, "You must call .Connect(strConnString) before executing any sql code."
			On Error Goto 0
		End If
	End Sub
 
Ok Try doing it like this

Code:
dim Connection 
Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("****")

Dim Recordset,strSQL 
strSQL = SELECT TOP 1 * FROM tblItemInfo where pid=0
Set Recordset = Connection.Execute(strSQL)

if not Recordset.eof then
  do while not Recordset.eof
     response.write(Recordset(0))
  loop
end if

}...the bane of my life!
 
ah ok cool, my code was wrong anyway lol. SHould have been
Code:
dim conn 
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("./db/login.mdb")

Dim rs,strSQL 
strSQL = "SELECT TOP 1 * FROM tblItemInfo where pid=0"
Set rs = conn.Execute(strSQL)

if not rs.eof then
  do while not rs.eof
     response.write(rs(0) & " "& rs(1) &"<br>")
	 rs.movenext
  loop
end if

}...the bane of my life!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top