www.webdeveloper.com
Results 1 to 5 of 5

Thread: Call Sub

  1. #1
    Join Date
    Jul 2006
    Posts
    12

    Call Sub

    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"

    Code:
    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

    Code:
    <%
    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

    Any ideas???

  2. #2
    Join Date
    Feb 2003
    Posts
    2,745
    Speed_Per_Ball is a Function, not a Sub

    Change first and last lines:
    Code:
    Function Speed_Per_Ball (result_query_id, result_run_id)
    ...
    ...
    End function
    ought 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

  3. #3
    Join Date
    Jul 2006
    Posts
    12
    Ok i changed the lines to Function, but i still get the same error message:

    Code:
    Microsoft VBScript compilation  error '800a03ea'
    
    Syntax error
    
    /cosa5web/callSpeed.inc, line 2
    
    Function Speed_Per_Ball (result_query_id, result_run_id)
    ^

  4. #4
    Join Date
    Feb 2003
    Posts
    2,745
    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

  5. #5
    Join Date
    Jul 2006
    Posts
    12
    It works now, thanks ... i just moved the include dirctive to the top of the asp file. Cheers

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles