1

次のスニペットを実行して許容値を入力すると、目的の結果が得られます。

do while len(strselect) = 0  'or strselect<>"1" or strselect<>"2" or strselect<>"3"
strselect = inputbox ("Please select:" &vbcrlf&vbcrlf&_  
"1. Add an entry" &vbcrlf&vbcrlf&_  
"2. Remove an entry" &vbcrlf&vbcrlf&_  
"3. Search for an entry" &vbcrlf, "Contact Book")
if isempty(strselect) then
wscript.quit()
elseif strselect="1" then
wscript.echo "You chose 1"
elseif strselect="2" then
wscript.echo "You chose 2"
elseif strselect="3" then
wscript.echo "You chose 3"
end if
loop

ただし、(条件にコメントを含めることによって) 検証プロセスをさらに制限しdo while、スニペットを再度実行すると、対応するif条件がトリガーされますが、doループは終了せずに継続します。

私はループ条件で使用してみましたが、isnumeric喜びはありません...ループを終了するために何が欠けていますか?cstrdostrselect

4

1 に答える 1

1

条件のロジックに問題があります

         condition 1            condition 2       condition 3       condition 4
         v----------------v     v------------v    v------------v    v............v
do while len(strselect) = 0  or strselect<>"1" or strselect<>"2" or strselect<>"3"

strselect 内の値に応じて、

value   c1      c2      c3      c4    
        len=0   <>"1"   <>"2"   <>"3"    c1 or c2 or c3 or c4
--------------------------------------   --------------------
empty   true    true    true    true            true
  1     false   false   true    true            true
  2     false   true    false   true            true
  3     false   true    true    false           true
other   false   true    true    true            true

各行には、少なくとも 1 つの条件が として評価され、条件を演算子 (値の少なくとも 1 つが true の場合は true に評価)trueで連結しているため、条件全体が true として評価され、コードはループし続けます。Or

条件を変えるしかない

Do While strselect<>"1" And strselect<>"2" And strselect<>"3"
Do While Not (strselect="1" Or strselect="2" Or strselect="3")
....
于 2016-09-30T07:03:13.877 に答える