日期:2014-05-17  浏览次数:20833 次

编号前加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 if
response.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