2015-10-20 39 views
0

我已经很难解决这个问题,但我很快就来了。在VBScript中,我无法阻止我的循环重复执行

这里是我的代码:

'attempts and completions loop 
    'attempts 
    do 
     do 
      Wscript.StdOut.WriteLine "How many attempts did " & QB & " throw: " 
      attempts = Wscript.StdIn.ReadLine 
      if IsNumeric(attempts) then 
       attempts = CInt(attempts) 
      else 
       Wscript.StdOut.Write "You did not enter a number. Please try again." 
      end if 
     loop while IsNumeric(attempts) = false 

     'completions 
     do 
      Wscript.StdOut.WriteLine "How many completed passes did " & QB & " throw for: " 
      completions = Wscript.StdIn.ReadLine 
      if IsNumeric(completions) then 
       attempts = CInt(completions) 
      else 
       Wscript.StdOut.Write "You did not enter a number. Please try again." 
      end if 
     loop while (completions) = false 
    if attempts > completions then 
     exit do 
    else 
     Wscript.StdOut.Writeline "Completions can not be more that attempts please try again." 
    end if 
    loop while attempts < completions 

当我尝试比输入更多的落成,让我的愿望的结果。但是当我输入更多的尝试而不是完成时,它仍然会循环访问这段代码。我可以请帮助吗?

+0

我认为缺少的则IsNumeric为(完工)只是复制/粘贴错字? 此外,当程序意外地循环时,它是否也显示“完成不能更多...”的消息还是只是循环? –

回答

0

没关系我的评论...我现在看到它。在完成循环中,当您应该设置完成变量时,您正在设置尝试变量。

if IsNumeric(completions) then 
      attempts = CInt(completions) 

所以当你比较时,尝试总是空白或者你初始化它的任何东西。

标准的复制/粘贴错误:)

+0

你也有一个失踪的数字 –

+1

非常感谢。这是一个漫长的一天。大声笑 –

+0

我仍然有同样的问题。无论输入什么号码来完成尝试和完成,它都会进入下一个提示,不允许我重试输入。 –