首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

编号前加0有关问题错在哪儿

2012-05-27 
编号前加0问题错在哪儿VBScript code%for i1 to 10if i10 thenif i10 thenProdId0&(i)elseProdId(

编号前加0问题错在哪儿

VBScript code
<%for i=1 to 10    if i<10 then        if i<10 then        ProdId="0"&(i)        else        ProdId=(i)        end if    elseif i<100 then        if i<10 then        ProdId="00"&(i)        elseif i<100 then        ProdId="0"&(i)        else        ProdId=(i)        end if    elseif i<1000 then        if i<10 then        ProdId="000"&(i)        elseif i<100 then        ProdId="00"&(i)        elseif i<100 then        ProdId="0"&(i)        else        ProdId=(i)        end if    else        ProdId=(i)    end ifresponse.write ProdId &"<br>"next%>


我这个编号前加0问题不知道错在哪儿,还是我写的不对,

我要达到的目录是
编号数字小于10的结果要
1
2
3
.....
8
9

编号数字小于100的结果要
01
02
03
.....
87
88
99

编号数字小于1000的结果要
001
002
003
.....
997
998
999

问题现在的结果是小于10也加0,小于100在10以上也加0.
结果是
01
02
03
......
07
08
09
010
011
012
.....
097
098
099
以此类推了,

[解决办法]
<%
dim intnum
intnum=101
for i=1 to intnum
if intnum<=10 then

ProdId=(i)

elseif intnum<=100 and intnum>10 then
if i<10 then
ProdId="00"&(i)
elseif i<100 then
ProdId="0"&(i)
else
ProdId=(i)
end if
elseif intnum<=1000 and intnum>100 then
if i<10 then
ProdId="000"&(i)
elseif i<100 then
ProdId="00"&(i)
elseif i<1000 then
ProdId="0"&(i)
else
ProdId=(i)
end if
else
ProdId=(i)
end if
response.write ProdId &"<br>"
next
%>

[解决办法]
探讨
额 可以先把i赋值给变量intnum

热点排行