2016-09-30 9 views
0

次のスニペットを実行して許容値を入力すると、目的の結果が得られます。私はさらに(do while条件における発言などによって)検証プロセスを制約し、再度スニペットを実行しようと入力ボックスでのユーザー入力の検証

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 

しかし、私は、対応するif条件がトリガ得るが、doループは続け、代わりに出ます。

私は私がループを終了するくそ事を得るために行方不明です...ない喜びで、doループstrselect条件にisnumericcstrを使用して試してみましたか?

答えて

0

あなたは、あなたが持っているstrselect内の値に応じて条件

  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" 

のロジックに問題がありますが、少なくとも1つの条件がtrueとして評価されている各ラインで

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 

、および Or演算子で条件を連結すると(少なくとも1つの値が真であれば真と評価されます)、完全条件は真として評価され、コードはループを維持します

あなたは唯一の条件に

Do While strselect<>"1" And strselect<>"2" And strselect<>"3" 
Do While Not (strselect="1" Or strselect="2" Or strselect="3") 
.... 
+0

本当にありがとうございましたMC ND、きれいに示す答えを変更する必要があります。私のエラーは今や明らかで、昨夜は不安定に決まりませんでした。私は論理的な演算子と私の論理を改訂します!あとがき...もう一度ありがとう! :) –