Click here to Skip to main content
15,888,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi friends i am executing a simple code as follows in vb script :
VB
dim a
a=inputbox("Enter the value of a")

select case a

  case (a<0)
     msgbox("a is less than zero")
  case (a<10)
     msgbox("a is less than 10")
  case (a>10 and a<20)
     msgbox("a is in between 10 and 20")
  case else
       msgbox("a is greater than 20")
end select

for every value of a ,i am getting output as a is greater than 20
can you explain where am i doing it wrong ?
Posted
Updated 1-May-15 8:23am
v2

1 solution

You cannot use comparation in cases, they must be values.
It could work for this:
VB
dim a

repeat:
a=inputbox("Enter the value of a between 0 and 5")
if a<0 or a>5 then
  msgbox("You entered an incorrect value")
  goto repeat
end if

select case a 
  case (0)
     msgbox("a is zero")
  case (1)
     msgbox("a is 1")
  case (2)
     msgbox("a is 2")
  case else
       msgbox("a is between 3 and 5")
end select


For what you want to do you have to use a chain of if else if.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900