no my code is as follows (I need to pass back teh code -- the error is just in case an error happened while getting it and I can't return it as the code variable or I won't know it's an error. (and if it's an error I display it in a different place then the code)
pin="123"
myerror=""
mycode=getmycode(pin)
function getmycode(pin)
'I get the code from teh db
if rs.bof and rs.eof then
myerror="error no such pin in db"
getmycode=error
It is a scoping issue. Looks like you aren't declaring your variables, so in the getmycode function, myerror is a local variable. Should always declare your vars. The way you have it, passing myerror by reference will solve the problem (see below), but I still reccomend declaring all variables. Option Explicit at the top of your script will help iron these types of issues out.
Code:
pin="123"
myerror=""
mycode=getmycode(pin, myerror)
function getmycode(byVal pin, byRef myerror)
'I get the code from teh db
if rs.bof and rs.eof then
myerror="error no such pin in db"
getmycode=error
else
getmycode=rs("code")
end if
end function
what db are you using? why check for bof and eof at same time? try just checking eof. need to add some debugging code to see where the problem is -- if the else block executes then myerror will still be empty string. try this
Code:
pin="123"
myerror=""
mycode=getmycode(pin, myerror)
Response.Write "myerror: " & myerror
function getmycode(byVal pin, byRef myerror)
'I get the code from teh db
'if rs.bof and rs.eof then
if rs.eof then
myerror="error no such pin in db"
'' What is this next line? should it be getmycode = myerror?
getmycode=error
Response.Write myerror
else
getmycode=rs("code")
Response.Write "No Error because we found pin in db"
end if
end function
Bookmarks