vbs basic tutorial (3) supplement

Note: This lesson is only a supplement to the third lesson !

supplement

When your program has to deal with many different judgment situations, elseif...then will make the program look messy, so there is a select case structure specifically to deal with this situation. The grammatical structure of select case is very simple:
  select case variable name
    case value
    statement
    case value
    statement
    case else
    statement
    end select
This kind of structure requires end select to end the statement. I will use the vernacular to talk about the meaning of the structure: the
opening sentence, the content is expanded by the variable name.
If a variable name is the first possibility:
The following statement is executed
if the variable name is the second possibility:
the following statement is executed
if the variable is the name of the first n possible:
The following statement is executed
or
execute the following statement to
the end of the statement
below Give a chestnut:

 dim a 
  a=inputbox("请输入1~3的值") 
  a=int(a) '处理inputbox返回字符串的问题
  select case a 
  case 1 
  msgbox "壹" 
  case 2 
  msgbox "贰" 
  case 3 
  msgbox "叁" 
  case else 
  msgbox "输入错误" 
  end select 

If converted to an if statement:

dim a 
  a=inputbox("请输入1--3的值") 
  a=int(a) 
  if a=1 then 
  msgbox "壹" 
  else if a=2 then 
  msgbox "贰" 
  else if a=3 then 
  msgbox "叁" 
  else 
  msgbox "输入错误" 
  end if 

Does this seem more cumbersome? Or the first one.

operation

Convert all positive integers within 5 to Chinese uppercase numbers

Note: There are big eggs in the next chapter!

Guess you like

Origin blog.csdn.net/CSDN_C2/article/details/105931273