2015-10-20 76 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

我仍然有同樣的問題。無論輸入什麼號碼來完成嘗試和完成,它都會進入下一個提示,不允許我重試輸入。 –

相關問題