SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    epsom
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Functions Question

    Hi

    Can anyone tell me if a variable can be passed outside of a function?

    In this function i pass variables to it to find out if a record exists, what i want to do next is call this function and if a record does not exist pass a variable out like Statement = False and then pick up that value on the page that i call the function.

    Can this be done? I was thinking perhaps using a Session?

    Is there a better way?

    Thanks

    Guys/Girls


    Function CheckEntry(dbconnection,table_name,id,m)

    dim rs
    set rs=server.createobject("adodb.recordset")

    sql = "Select * " & " FROM " & table_name & " where CustomerID = " & id & " AND Month = " & m

    rs.open sql, dbconnection

    If rs.EOF Then

    Response.Write "No Record exists"'Now do the insert

    Else

    Response.Write "Record exists"

    End If
    end function

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it would be,

    If rs.EOF Then

    CheckEntry = 1

    Else

    CheckEntry = 0

    End If

    then all you do is this:

    if CheckEntry("dsnname","testtable","324234","September") = 1 then

    write fail message or script

    else

    write success message or script

    end if

    what your looking at doing there is a sub, change the function to sub ( as well as end function to end sub ) then use either <% call CheckEntry("","","","") %> or when in a script remove the <% and %> and use call CheckEntry("","","","")

    But either one will do.

    Gav


Bookmarks

Posting Permissions

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