Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    Cannot use parentheses when calling a Sub

    What's wrong here?

    Code:
    Microsoft VBScript compilation error '800a0414'
    
    Cannot use parentheses when calling a Sub
    
    /nightclub_photography/asp/moveFile.asp, line 68
    
    add_to_database("images","jpg,img_set,sdate,sold,upload_time",sql)
    ------------------------------------------------------------------^
    PHP Code:
    'Get the jpg name ready to add to database
            jpg_name = split(i.name, ".")
            
            
            sql="'" & jpg_name(0)
            sql=sql & "'," & uploadNum
            sql=sql & ",'" & Request.Cookies("
    sdate")
            sql=sql & "',0,'"&upload_time&"'"
            
            '
    Add to database
            add_to_database
    ("images","jpg,img_set,sdate,sold,upload_time",sql)
            
            
    on error resume next 
    PHP Code:
    function add_to_database(where,column,values)
        
    'Create connection
        set conn=Server.CreateObject("ADODB.Connection")
        conn.Provider="Microsoft.ACE.OLEDB.12.0"
        conn.Open Server.MapPath("/nightclub_photography/data/database/jamsnaps.mdb")
        
        '
    Check content is safe
        
    'safe_values = strip_special(values)
        
        '
    Create query
        sql 
    "INSERT INTO " where " (" column ") VALUES " values
        
        response
    .write(sql)
        
    Destroy connection
        conn
    .close
        sql 
    ""
    end function 
    Not finished the function yet obviously, just checking if the query is being created correctly.

    Edit: fixed this by removing the "( )" from the function call, strange issue if someone can explain why I had to do that please.
    Last edited by martynball; 06-09-2013 at 06:44 PM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,014
    Thanks
    79
    Thanked 4,435 Times in 4,400 Posts
    It's just a rule in VBScript.

    When you call a SUB (or even a FUNCTION that you *use* like a SUB), you aren't allowed to put parens around the arguments. Here's the funny part: You *CAN* do so if you use the keyword CALL.

    Thus:
    Code:
    Call add_to_database("images","jpg,img_set,sdate,sold,upload_time",sql)
    will work just fine.

    It's why it is technically wrong to use parens with Response.Write:
    Code:
    BAD:
    Response.Write("this is wrong")
    GOOD:
    Response.Write "this is good"
    Why does it work with Response.Write? Because there is only one argument, and with one argument, the parens could be part of an expression. Example:
    Code:
    Response.Write ( "a" & ( b - 7 ) ) & "c"
    Just as a for instance, *THIS* would be legal:
    Code:
    add_to_database ("images"), ("jpg,img_set,sdate,sold,upload_time"), (sql)
    because each expression is allowed to have parens around it, as part of the expression (not an integral part of the SUB call).
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (06-09-2013)


  •  

    Posting Permissions

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