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

Function Problem

Status
Not open for further replies.

jotap

Technical User
Apr 8, 2005
12
PT
Hi there...!

I have a problem when calling a function that returns a recordset value. Here's my problem:

sub main
...
call WriteCatalog(rs("productname"),..., GetName(rs("manufacturercode")),...)
...
end sub

sub WriteCatalog(prodname,...,manufacturer,...)
response.write "<table>...manufacturer...prodname...</table>"
end sub

function GetName(Code)
declare recordset
set recordset=connection.execute...

GetName=recordset(0).value

recordset.close
set recordset=nothing
end function

Now, i doesn't get an error but, if take off the function the code works well, if not the page isn't written. where do you think the problem may be?? i´ve also tried to call the function from the WriteCatalog sub but it also doesn't work.

thanks in advance
 
Try this:

Code:
function GetMarca(Cod)
  Dim SQLMarcas
  Dim RSMarcas

  If Not IsNumeric(Cod) then
    'Bad Input
    GetMarca = -1
    exit function
  End if

  SLQMarcas = "SELECT Marcas.Nome "
  SLQMarcas = SLQMarcas & "FROM Marcas "
  SLQMarcas = SLQMarcas & "WHERE Marcas.Cod = " & Cod 

  Set RSMarcas = Server.CreateObject("adoDB.recordset")
  set RSMarcas = Conn.Execute(SLQMarcas)

  If RSMarcas.State <> 1 then
    'Error opening recordset
    GetMarca = -2
    RSMarcas.close
    set RSMarcas = Nothing
    exit function
  end if

  if RSMarcas.EoF then
    'No records match Cod
    GetMarc a = 0
  else
    'set return value
    GetMarca = RSMarcas(0)
  end if

  RSMarcas.close
  set RSMarcas = Nothing
end function

There are 2 possible errors, -1 and -2. If the record is not found it will return 0.
 
here's one problem:
I've tried:
Response.Write "<BR>Entered GetMarca with Codigo=/" & Codigo & "/<BR>"
and i got:
Entered GetMarca with Codigo=/1/

Entered GetMarca with Codigo=/1/
 
It's working...............
i've tried the code and it worked. thanks a lot.
But just to understant, what or where was the problem the way it was???
 
basically the code is the same but with debugging. I don't understand why it works only now. what do you think?
 
Perhaps only a flush issue ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
It was probably not working because of the solar eclipse.
 
Hei, don't get me wrong. I'm very thankful for your help. All of you. I was just trying to understand because unfortunaly i'm new in programming.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top