Click to See Complete Forum and Search --> : Call Sub


chooby
08-21-2006, 11:46 AM
Hi im using the follwoing code to call a sub/function which is in a different file, but get an error message for the inc file. Basically what i want to do is to pass the result_query_id & result_run_id variables to the function, which will calculate the number and pass that number back to the main page and save it into the variable "answer"

result_query_id = Rs2("query_id")
result_run_id_temp = Rs2("next_run")
result_run_id = result_run_id_temp - 1

%>
<!-- #INCLUDE FILE="callSpeed.inc"-->
<%

answer = Speed_Per_Ball(result_query_id, result_run_id)
Response.Write (answer)
Response.Write ("<br />")

But then i get this error

Microsoft VBScript compilation error '800a03ea'

Syntax error

/cosa5web/callSpeed.inc, line 2

sub Speed_Per_Ball (result_query_id, result_run_id)
^

here is the code for the callSpeed.inc file

<%
sub Speed_Per_Ball (result_query_id, result_run_id)

Tot_Speed = 0
Tot_Balls = 0

set Cn3=server.createobject("ADODB.connection")
set Rs3=server.createobject("ADODB.recordset")
Cn3.open dsn
sql3 = "select * from Hawk_Eye where (query_id = '" & result_query_id & "') and (run_id = '" & result_run_id & "')"
Rs3.open sql3, Cn3
if Rs3.eof <> true then
while not Rs3.eof
Tot_Speed_temp = Rs3("Speed_at_Release")
Tot_Speed = Tot_Speed + Tot_Speed_temp
Tot_Balls = Tot_Balls + 1
Rs3.movenext
wend
end if
set Rs3=nothing
Cn3.close

Speed_Per_Ball = Tot_Speed / Tot_Balls

End sub
%>

I was following the code from Link (http://www.webdeveloper.com/forum/showthread.php?t=22710)

Any ideas???

russell
08-21-2006, 12:43 PM
Speed_Per_Ball is a Function, not a Sub

Change first and last lines:

Function Speed_Per_Ball (result_query_id, result_run_id)
...
...
End functionought to add something in there to prevent divide by 0 error if Tot_Balls = 0. also you need to close your recordset, and set cn3 to nothing

chooby
08-21-2006, 01:26 PM
Ok i changed the lines to Function, but i still get the same error message:

Microsoft VBScript compilation error '800a03ea'

Syntax error

/cosa5web/callSpeed.inc, line 2

Function Speed_Per_Ball (result_query_id, result_run_id)
^

russell
08-21-2006, 03:52 PM
try this

1. move the include dirctive to the very top of your asp file
2. remove the space between <!-- and #Include <!-- #INCLUDE FILE="callSpeed.inc"-->
should be <!--#INCLUDE FILE="callSpeed.inc"-->

finally, did u post all of the code of the include file.

oh yeah, and it should have an asp extension, not inc.

also, lets see all of the code from the calling page

chooby
08-22-2006, 08:41 AM
It works now, thanks ... i just moved the include dirctive to the top of the asp file. Cheers :)