Validating user input in inputbox

前端 未结 1 1057
鱼传尺愫
鱼传尺愫 2021-01-15 20:47

When I run the following snippet, and enter an acceptable value, I get the desired result.

do while len(strselect) = 0  \'or strselect<>\"1\" or strsel         


        
相关标签:
1条回答
  • 2021-01-15 21:07

    You have a problem with the logic in the condition

             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"
    

    Depending on value inside strselect, you have

    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
    

    In each line you have at least one condition evaluated as true, and as you are concatenating the conditions with Or operators (evaluate to true if at least one of the values is true), the full condition is evaluated as true and the code keeps looping

    You only need to change the condition

    Do While strselect<>"1" And strselect<>"2" And strselect<>"3"
    Do While Not (strselect="1" Or strselect="2" Or strselect="3")
    ....
    
    0 讨论(0)
提交回复
热议问题