返回列表 发帖

[问题求助] vbs if……else语句改成select case语句

本帖最后由 pcl_test 于 2016-9-3 13:32 编辑

教程裡的例題:輸入0-100的分數並根據0-20、20-40、40-60、60-80、80-100顯示a、b、c、d、e的等級,我用if 可以寫得出來,

教程又說明用select case會更加簡潔,可惜沒有範例解答,我是初學還寫不出來,希望有人能指導一下,幫我建立正確的觀念,謝謝!
option explicit
dim a
a = inputbox ("輸入分數0-100:")
if a>=0 and a<=20 then
   msgbox "e等"
elseif a>=21 and a<=40 then
   msgbox "d等"
elseif a>=41 and a<=60 then
   msgbox "c等"
elseif a>=61 and a<=80 then
   msgbox "b等"
elseif a>=81 and a<=100 then
   msgbox "a等"
else
   msgbox "輸入錯誤"
end ifCOPY

Dim var
Do
  var=InputBox("输入分数0-100:")
Loop Until IsNumeric(var) '判断是否为数字
Select Case True
  Case var>=0 And var<=20 : MsgBox "e等"
  Case var>20 And var<=40 : MsgBox "d等"
  Case var>40 And var<=60 : MsgBox "c等"
  Case var>60 And var<=80 : MsgBox "b等"
  Case var>80 And var<=100 : MsgBox "a等"
  Case Else  MsgBox "输入有误!"
End Select COPY
1

评分人数

TOP

原帖由 broly 于 2011-1-22 20:46 发表
Dim var
Do
  var=InputBox("输入分数0-100:")
Loop Until IsNumeric(var) '判断是否为数字
Select Case True
  Case var>=0 And var20 And var40 And var60 And var80 And var



感謝!

TOP

返回列表