我在编写将输出记录数组的函数时遇到问题。我试图做的是调用一个函数来获取表中的所有记录,并将创建一个多维数组,我可以在调用该函数的页面中使用该数组。
你能告诉我我做错了什么吗?
function get_admins
set rs = Server.CreateObject("ADODB.recordset")
rs.cursorType = 3
getsql = "select * from users order by name asc"
rs.Open getsql, conn
total = rs.RecordCount
ra = array
c = 0
if total < 1 then
o = "There are no admins yet."
else
do until rs.EOF
id = rs.Fields("id").value
username = rs.Fields("username").value
adminname = rs.Fields("name").value
email = rs.Fields("email").value
Redim Preserve ra(c,4) '<-- This is the line the error doesn't like
ra(c,0) = id
ra(c,1) = username
ra(c,2) = adminname
ra(c,3) = email
c = c + 1
rs.MoveNext
loop
end if
rs.close
get_admins = ra
end function
这是我得到的错误:
Microsoft VBScript 运行时错误“800a0009”
下标超出范围
页面上的函数调用如下所示:
<pre><%
dim seeme
set seeme = get_admins
%></pre>
以下是我发现的一些类似问题:
Classic ASP 3.0 Create Array from a Recordset - 帮助很大,但还不够。
Redim Preserve 给出了“下标超出范围” ——这让我很困惑。