【问题标题】:Infinite while loop in VBAVBA中的无限while循环
【发布时间】:2013-12-19 05:30:12
【问题描述】:

谁能看到我下面的while循环有什么问题?基本上我想要求用户输入“m”或“w”,但是,当我运行时,尽管用户输入了“m”或“w”,但它似乎进入了一个无限循环。

While period <> "m" Or period <> "w"
    period = InputBox(Prompt:="Please enter the period (m/w): ", Title:="Period")
Wend

【问题讨论】:

  • 感谢 Kevin 和 Daniel,工作完美:D

标签: excel vba while-loop


【解决方案1】:

这是一个无限循环,因为 if period = "m" then period &lt;&gt; "w" 反之亦然

切换到以下可能是您想要的。

While period <> "m" AND period <> "w"
    period = InputBox(Prompt:="Please enter the period (m/w): ", Title:="Period")
Wend

【讨论】:

    【解决方案2】:

    我认为您的意思是 And 而不是 Or 几乎任何输入都不会是“w”或“m”,包括 w 和 m。 (w 不等于 m,因此条件仍然为真,反之亦然)。

    【讨论】:

      猜你喜欢
      • 2014-03-29
      • 2012-12-24
      • 2015-06-25
      • 2013-02-22
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      • 2012-08-28
      • 1970-01-01
      相关资源
      最近更新 更多