注册 登录
编程论坛 ASP技术论坛

为什么我的会无限次的循环,明明已经编写了强制退出和条件了

a124211741 发布于 2011-04-04 15:35, 603 次点击
程序代码:
<script language="vbscript">
dim a,b,c,d,e,panding
panding = 0
c = 0
do while c = 0
do while panding = 0
a = inputbox("请输入一个成绩进行判定")
if a = false then
    exit do
end if
    if isnumeric(a) then
        if a<=100 and a>0 then
            panding = 1
            select case true
                case a>90 and a<= 100
                    msgbox"你的成绩优秀"
                case a>80
                    msgbox"你的成绩良好"
                case a>70
                    msgbox "你的成绩中"
                case a>60
                    msgbox "你的成绩及格"
                case a<60
                    msgbox "你的成绩不及格"
            end select
        else
            msgbox"你输入的成绩超过有效范围,请重新输入"
        end if
    else
    msgbox"你输入的是非法字符,无法识别请重新输入"
end if
loop
b = msgbox("你是否要继续对成绩进行判定",1+32,"提示")
if b = false then
    c = 1    ------------------------>  之前这里是用exit do 但是也无效
end if
loop
</script>
8 回复
#2
a1242117412011-04-04 15:43
做一个补充
程序代码:
b = msgbox("你是否要继续对成绩进行判定",1+32,"提示")

if b = false then
    c = 1    ------------------------>  之前这里是用exit do 但是也无效
else

 panding = 0
end if

就是说我用msgbox 的时候点击取消按钮将会退出这个大循环,但是我现在的代码的b 值无法等于 false  
#3
yms1232011-04-05 14:32
LZ的代码想做什么?连续判断成绩?
#4
a1242117412011-04-05 18:16
1--第一个while循环是用来判断你是否要继续进行成绩的判断
2--第二个while 是对所输入的成绩进行判定,如果不符合条件则继续循环,一直到你输入的成绩符合条件为止。
3--当你成功的进行成绩判断的时候就会进入msgbox 这个地方,他会提示你是否还要继续进行成绩的判定
4--msgbox这里有用确定和取消按钮,当你点击确定的时候他会继续循环,反回第二步这个地方继续循环,点取消的时候他就会跳出这个while循环。不在执行任何语句
#5
hams2011-04-06 08:54
b = false
先看条件是否成立
#6
a1242117412011-04-06 18:47
很明显条件不成立,我用的是msgbox   里面有 确定和 取消的按钮,但是不论点确定还是取消的按钮其结果都是一样,我主要想问的是如何获取 msgbox 的这个确定和取消的值还是说msgbox这里面的值是无法取得的,需要用另外的方法
#7
twtrwr2011-04-06 21:03
根据MSDN
对于由数值类型的值转换为Boolean类型的值来说,0将转换为False,一切非0的值将转换为True。
而 msgbox 的返回值如下
MsgBox 函数有以下返回值:
常数 值 按钮  
vbOK 1 确定  
vbCancel 2 取消  
vbAbort 3 放弃  
vbRetry 4 重试  
vbIgnore 5 忽略  
vbYes 6 是  
vbNo 7 否
对于这些返回值转化为bool类型的都为真,所以一直会循环

还有你的这个select语句后面的表达式有点不妥。。。select case true  最好改为select case a
希望我的回答对你有用,,呵呵
#8
a1242117412011-04-06 22:46
回复 7楼 twtrwr
谢谢你的回答,但是当你把ture改成a 的时候 下面的a的取值范围就会有错误。得到的效果不理想
msgbox的取值不能像inputbox那样取值,至于boolean 这个函数的话我也理解。
我的问题其实就是想能不能将msgbox的取值(也就是确定和取消按钮)变的像inputbox那样可以获取 true 和false 2哥值
#9
yms1232011-04-07 13:46
程序代码:
<script language="vbscript">
dim score,iscontinue
sub InputScore()
      score=inputbox("请输入一个成绩进行判定","标题","")
      if score="" then
           msgbox "成绩不能为空"
           call InputScore()
           exit sub
      end if
      if not isnum(score) then
           msgbox "成绩不是整数"
           call InputScore()
           exit sub
      end if
      if cint(score)<60 then
           msgbox "不及格"
      elseif cint(score)>60 and cint(score)<70 then
           msgbox  "中等"
      elseif cint(score)>70 and cint(score)<80 then
           msgbox "良好"
      elseif cint(score)>80 and cint(score)<100 then
            msgbox "优秀"
      end if
      iscontinue=msgbox("是否继续判断成绩?",1,"标题")
      if iscontinue=1 then
         call InputScore()
      end if
end sub
function isnum(val)
    on error resume next
     if vartype(cint(val))<>2 then
          isnum=false
     else
          isnum=true
     end if
end function
call InputScore()

</script>
1