检查函数是否写了什么?

时间:2018-01-28 02:27:42

标签: vbscript asp-classic

我有一个使用密钥查询数据库并写入与该密钥相关的一些数据的函数。我想检查是否有任何结果返回但没有一个有效:

function special(key)
    'some code to querying to database and get a result
     response.write result
    'also response.write combination of html and texts and number
    ' if (some conditions) then (also response.write something more)
end function

首先尝试:

if special("fp") then
 response.write "found"
end if

第二次尝试:

if not(isNull(special("fp"))) then
 response.write "found"
end if

1 个答案:

答案 0 :(得分:1)

正如@Ansgar指出的,你需要你的函数来返回一些东西。所以如果你的功能如下:

function special(key)
    'some code to querying to database and get a result
     response.write result
    'also response.write combination of html and texts and number
    ' if (some conditions) then (also response.write something more)

    ' to determine if data was returned, you would need the following line. It assumes you have a recordset variable named rs that either returns data or not
    special = rs.BOF and rs.EOF
end function

如果rs.BOF为真,并且RS.eof为真,则没有找到fata:

if special("fp") then
    Response.Write "no value found"
else
    ' data was found, proceed with whatever happens next on the page