asp字符串和数字转换问题求助,立即揭帖

yoyoxo 2003-07-07 10:04:41
传入起始位置n1,终止位置n2,步长step,打印出n1,n3中的值:n1,n1+step,n1+2*step,....一直到<=n2为止。

比如:test.asp?n1=3&n2=64&step=4

在我的asp里怎么写?
n1=Request.QueryString("n1")
n2=Request.QueryString("n2")
step=Request.QueryString("step")
s=n1
n3=n1
while (n3+step)<=n2
s=s+","+(n3+step)
n3=n3+step
wend
Response.Write s

执行asp表明上面的是错的,死循环。因为n3,step都是字符串,n3+step是不是两将字符串连起来了,而不是相加??怎样让它们相加?
请帮忙改正上面的代码,谢谢!!
...全文
224 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
LonelyStark 2003-07-07
  • 打赏
  • 举报
回复
总是是用转换函数
cint clng等
楼上的都说完了
Cooly 2003-07-07
  • 打赏
  • 举报
回复
n1=Request.QueryString("n1")
n2=Request.QueryString("n2")
step=Request.QueryString("step")
if isNumeric(n1) and isNumeric(n2) and isNumeric(step) and instr(n1,".")=0 and instr(n2,".")=0 and instr(step,".")=0 then
n1=clng(n1)
n2=clng(n2)
step=clng(step)
else
response.write "Error"
response.end
end if

s=n1
n3=n1

while (n3+step)<=n2
s=s+","+(n3+step)
n3=n3+step
wend
Response.Write s
Reker熊 2003-07-07
  • 打赏
  • 举报
回复
n1=CInt(Request.QueryString("n1"))
n2=CInt(Request.QueryString("n2"))
step=CInt(Request.QueryString("step"))
s=CStr(n1)
n3=n1
while (n3+step)<=n2
s=s&","&CStr((n3+step))
n3=n3+step
wend
Response.Write s
cqfeng 2003-07-07
  • 打赏
  • 举报
回复
cint(),clng()
sinzy 2003-07-07
  • 打赏
  • 举报
回复
使用CInt()将字符串转换为整型数。

28,391

社区成员

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

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