看板 Programming 關於我們 聯絡資訊
我是程式新新新新手 煩請大家幫忙指導一下 最近寫了一個判斷電影分級的程式 普遍級:一般皆可觀賞 保護級:未滿六歲不得觀賞 六歲以上十二歲家長陪同觀賞 輔導級:未滿十二歲不得觀賞 十二歲以上未滿十八歲家長陪同觀賞 限制級:未滿十八歲不可觀賞 input Y=年齡 M=分級(普 護 輔 限 其中一個字串) 我用ifelse 寫的出來 程式大概這樣 <% Dim Y As Integer = 20, M As String = "輔" Response.Write("請輸入年齡:" & Y & "請輸入分級:" & M & "<BR>") If M = "保" And Y < 6 Then Response.Write("N," & "未滿六歲不得觀賞") ElseIf M = "保" And Y >= 6 And Y < 12 Then Response.Write("N," & "需長輩陪同") ElseIf M = "保" And Y >= 12 Then Response.Write("Y," & "可觀賞") ElseIf M = "輔" And Y < 12 Then Response.Write("N," & "未滿十二歲不得觀賞") ElseIf M = "輔" And Y >= 12 And Y < 18 Then Response.Write("N," & "需長輩陪同") ElseIf M = "輔" And Y >= 18 Then Response.Write("Y," & "可觀賞") ElseIf M = "限" And Y < 18 Then Response.Write("N," & "未滿十八歲不得觀賞") ElseIf M = "限" And Y >= 18 Then Response.Write("Y," & "可觀賞") Else Response.Write("Y," & "皆可觀賞") End If %> 異想天開用if加上case結果是殘念 如下 <% Dim Y As Integer = 7, M As String = "輔" Response.Write("請輸入年齡:" & Y & "請輸入分級:" & M & "<BR>") If M = "保" Then Select Case Y Case Y < 6 Response.Write("N" & "未滿六歲不得觀賞") Case Y >= 6 And Y < 12 Response.Write("N" & "需長輩陪同") Case Y >= 12 Response.Write("Y" & "可觀賞") End Select ElseIf M = "輔" Then Select Case Y Case Y < 12 Response.Write("N" & "未滿十二歲不得觀賞") Case Y >= 12 And Y < 18 Response.Write("N" & "需長輩陪同") Case Y >= 18 Response.Write("Y" & "可觀賞") End Select ElseIf M = "限" Then Select Case Y Case Y < 18 Response.Write("N" & "未滿十八歲不得觀賞") Case Y >= 18 Response.Write("Y" & "可觀賞") End Select Else Response.Write("Y" & "皆可觀賞") End If %> 請問版各位大哥大姐 有這種if case的寫法嗎 如果沒有 原來的ifelse 有更好的寫法嗎 感覺又臭又長的 感謝指導 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.117.117.58
LPH66:select case 不是這樣寫的.... 140.112.250.80 08/18 16:35
LPH66:回去翻書 裡面應該會教你怎麼寫 140.112.250.80 08/18 16:37
MOONRAKER:可他是VB啊 VB的case超多功能 爆無聊的 59.120.168.228 08/18 19:48
LPH66:就算是VB的select case也不用把Y寫進去... 140.112.250.80 08/18 21:39
tellalie:樓上大哥我不懂您的意思,我看書中VB的 122.117.117.58 08/18 22:24
tellalie:case可以判斷範圍例如case Y<=5表五以下 122.117.117.58 08/18 22:25
tellalie:都成立,case"A"To"Z"表A到Z都符合 122.117.117.58 08/18 22:26
tellalie:能多給愚笨的小弟一些提示嗎 謝謝 122.117.117.58 08/18 22:26
MOONRAKER:你在VB畫面上打出來不會自動修正嗎? 125.232.96.108 08/19 05:36