这个问题,难住不少人........

freeweb 2008-01-28 10:34:45
源代码如下:
<!--#include virtual="/include/conn.asp" -->
<%
set rs1=server.CreateObject("adodb.recordset")
rs1.open "select * from Ty_users where Cid=6 and Spd='1'",conn,1,1
if not rs1.eof then
ReDim Uc(rs1.recordcount)
rs1.movefirst
for i=0 to rs1.recordcount-1
Uc(i)=rs1("id")
rs1.movenext
next
rs1.movefirst
end if
rs1.close
set rs1=nothing
%>
<table>
<%

for i=2 to 15
Sjr=0
Allid=""

for j=0 to Ubound(Uc)
set rs2=server.CreateObject("adodb.recordset")
rs2.open "select * from Ty_users where Cid="&Cint(Uc(j))&" and Spd='1'",conn,1,1
if not rs2.eof then
Sjr=Sjr+rs2.recordcount
end if

while not rs2.eof
Allid=Allid&rs2("id")&","
rs2.movenext
wend
rs2.close
set rs2=nothing
next
%>
<tr>
<td align="center"><%= i %></td>
<td align="center"><%= 3^i %></td>
<td align="center"><%= Sjr %></td>
<td align="center">=<%=3^i-Sjr %></td>
</tr>
<%
Redim Uc(Sjr)
Ac=split(Allid,",")

for k=0 to Ubound(Ac)
Uc(k)=Ac(k)
next
next
%>
</table>


错误类型:
Microsoft VBScript 运行时错误 (0x800A000D)
类型不匹配: 'Cint'

Uc定义的动态数组,并且赋值,为什么会出错?如果不加Cint,出现参数为空的错误提示。UC是肯定有数据的。这问题是出在那里呢?在线急等!
...全文
135 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Cyberdragontech 2008-01-28
  • 打赏
  • 举报
回复
rs2.open "select * from Ty_users where Cid="&Cint(Uc(j))&" and Spd='1'",conn,1,1

应该是这行错了,检查一下U(j)是否有空值的情况
  • 打赏
  • 举报
回复
呵呵,何必直接给答案他呢!看看我在7#的回复,只是给他提个醒!让他自己用简单的例子去做比较再检查程序,这有助于他学习!直接给答案,印象不会太深!下次还会范这样的毛病
一路向北123 2008-01-28
  • 打赏
  • 举报
回复
你 ReDim Uc(rs1.recordcount) 是定義了Uc的長度為rs1.recordcount+1個
而你給Uc赋值時卻只赋了rs1.recordcount個,所以當你作for j=0 to Ubound(Uc) 循環時會多出一個空值
把ReDim Uc(rs1.recordcount) 改為ReDim Uc(rs1.recordcount-1) 或
for j=0 to Ubound(Uc) 改為 for j=0 to Ubound(Uc)-1 即可
myvicy 2008-01-28
  • 打赏
  • 举报
回复
CInt 函数
返回表达式,此表达式已被转换为 Integer 子类型的 Variant。

CInt(expression)

expression 参数是任意有效的表达式。

说明
通常,可以使用子类型转换函数书写代码,以显示某些操作的结果应被表示为特定的数据类型,而不是默认类型。例如,在出现货币、单精度或双精度运算的情况下,使用 CInt 或 CLng 强制执行整数运算。

CInt 函数用于进行从其他数据类型到 Integer 子类型的国际公认的格式转换。例如对十进制分隔符(如千分符)的识别,可能取决于系统的区域设置。

如果 expression 在 Integer 子类型可接受的范围之外,则发生错误。

下面的示例利用 CInt 函数把值转换为 Integer:

Dim MyDouble, MyInt
MyDouble = 2345.5678 ' MyDouble 是 Double。
MyInt = CInt(MyDouble) ' MyInt 包含 2346。
注意 CInt 不同于 Fix 和 Int 函数删除数值的小数部分,而是采用四舍五入的方式。 当小数部分正好等于 0.5 时, CInt 总是将其四舍五入成最接近该数的偶数。例如, 0.5 四舍五入为 0, 以及 1.5 四舍五入为 2.
tvruuiqpl1314520 2008-01-28
  • 打赏
  • 举报
回复
Cint(Uc(j))你这个转换后,与数据库里面的字段类型不符,最好是查询后在转换
  • 打赏
  • 举报
回复
for j=0 to Ubound(Uc)
你应该错在这句!我举一个简单的例子给你
ReDim Uc(4)
Uc(0)=1
Uc(1)=2
Uc(2)=3
Uc(3)=4
for j=0 to Ubound(Uc)-1
response.Write Uc(j)
next

ReDim Uc(4)
Uc(0)=1
Uc(1)=2
Uc(2)=3
Uc(3)=4
for j=0 to Ubound(Uc)
response.Write Uc(j)
next

比较下2个的结果,然后再看看你的程序!你不用cint而用int再看看
一路向北123 2008-01-28
  • 打赏
  • 举报
回复
ReDim Uc(rs1.recordcount) 改為 ReDim Uc(rs1.recordcount-1)
littlelam 2008-01-28
  • 打赏
  • 举报
回复

if Uc(j)&""<>"" and IsNumeric(Uc(j)&"") then
set rs2=server.CreateObject("adodb.recordset")
rs2.open "select * from Ty_users where Cid="&Cint(Uc(j))&" and Spd='1'",conn,1,1
if not rs2.eof then
Sjr=Sjr+rs2.recordcount
end if

while not rs2.eof
Allid=Allid&rs2("id")&","
rs2.movenext
wend
rs2.close
set rs2=nothing
end if


wj121284 2008-01-28
  • 打赏
  • 举报
回复
在SQL文里面建议不要用函数,SQL自带的除外,你把转换放到外面试试
littlelam 2008-01-28
  • 打赏
  • 举报
回复

if Uc(j)&""<>"" then
set rs2=server.CreateObject("adodb.recordset")
rs2.open "select * from Ty_users where Cid="&Cint(Uc(j))&" and Spd='1'",conn,1,1
if not rs2.eof then
Sjr=Sjr+rs2.recordcount
end if

while not rs2.eof
Allid=Allid&rs2("id")&","
rs2.movenext
wend
rs2.close
set rs2=nothing
end if
littlelam 2008-01-28
  • 打赏
  • 举报
回复
先不转换
Response.Write 出来看看是什么东西
freeweb 2008-01-28
  • 打赏
  • 举报
回复
在线急等,等待有高手能指明~
  • 打赏
  • 举报
回复
100%有空值!

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧