找回密码
 加入
搜索
查看: 4687|回复: 5

[AU3基础] 关于Switch ... EndSwitch语句(锁贴)

  [复制链接]
发表于 2013-9-20 11:41:41 | 显示全部楼层 |阅读模式
本帖最后由 old_snoopy 于 2013-9-20 22:33 编辑

如下例1和例2应该功能一样,当例2输入0-59之间的数报错.求大侠指点(<=)

例1.
Dim $s
$s=InputBox("","请输入学生成绩:",'')  
Switch $s
  Case 89<$s And $s<=100
    MsgBox(0,"学生成绩","优秀!")
  Case 79<$s And $s<=89
    MsgBox(0,"学生成绩","良好!")
  Case 59<$s And $s<=79
    MsgBox(0,"学生成绩","及格!")
Case 0<$s And $s<=59       
    MsgBox(0,"学生成绩","不及格!")
Case $s=0       
    MsgBox(0,"学生成绩","不及格!")       
  Case Else
    MsgBox(0+16,"学生成绩","学生成绩输入错误!")
EndSwitch
例2.
Dim $s
$s=InputBox("","请输入学生成绩:",'')  
Switch $s
  Case 89<$s And $s<=100
    MsgBox(0,"学生成绩","优秀!")
  Case 79<$s And $s<=89
    MsgBox(0,"学生成绩","良好!")
  Case 59<$s And $s<=79
    MsgBox(0,"学生成绩","及格!")
  Case 0=<$s And $s<=59
    MsgBox(0,"学生成绩","不及格!")
  Case Else
    MsgBox(0+16,"学生成绩","学生成绩输入错误!")
EndSwitch
发表于 2013-9-20 18:36:02 | 显示全部楼层
回复 1# old_snoopy


    Switch ....不是这样用的. 应该这样:
Dim $s
$s=InputBox("","请输入学生成绩:",'')  
Switch $s
  Case 90 To 100
    MsgBox(0,"学生成绩","优秀!")
  Case 80 To 89
    MsgBox(0,"学生成绩","良好!")
  Case 60 To 79
    MsgBox(0,"学生成绩","及格!")
  Case 0 To 59
    MsgBox(0,"学生成绩","不及格!")
  Case Else
    MsgBox(0+16,"学生成绩","学生成绩输入错误!")
EndSwitch
 楼主| 发表于 2013-9-20 20:23:21 | 显示全部楼层
回复 2# user3000
我把原程序修改了一下,运行没问题!这程序所用语法与帮助文档不一致.是帮助文档简化了?

Dim $s
$s=InputBox("","请输入学生成绩:",'',' m')  
If @error=1 Then
   MsgBox(0+16+262144,"学生成绩","学生成绩输入错误!")
   Exit
EndIf
Switch $s
  Case $s>89 and $s<=100
    MsgBox(262144,"学生成绩","优秀!")
  Case $s>79 and $s<=89
    MsgBox(262144,"学生成绩","良好!")
  Case $s>59 and $s<=79
    MsgBox(262144,"学生成绩","及格!")
  Case $s>=0 and $s<=59
    MsgBox(262144,"学生成绩","不及格!")
  Case Else
    MsgBox(0+16+262144,"学生成绩","学生成绩输入错误!")
EndSwitch
发表于 2013-9-20 20:36:17 | 显示全部楼层
回复 3# old_snoopy


    If @error=1 Then
   MsgBox(0+16+262144,"学生成绩","学生成绩输入错误!")
   Exit
EndIf

这段应该可以删掉,毕竟下面已经有判断了...

没发现与2楼有什么不同的,>89且<=100意思跟90-100之间有什么区别?

另外楼主的0=<$S这样的写法不对吧,这样写的意思就是判断0,而非判断$S了...


新手表示:我啥也不知道啊啥也没说过...
发表于 2013-9-20 20:45:18 | 显示全部楼层
本帖最后由 user3000 于 2013-9-20 20:46 编辑

回复 3# old_snoopy

你这样用当然也是对的,我2楼说的不是这样用, 潜在意思是你的代码过于繁琐了.
编程的代码应该尽可能简洁明了地实现功能才是.

还有编辑的标题,有个错别字, 应该是 '已解决', 要用已经的那个 "已"
 楼主| 发表于 2013-9-20 21:50:32 | 显示全部楼层
本帖最后由 old_snoopy 于 2013-9-20 22:34 编辑

回复 5# user3000

搞错了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-26 21:21 , Processed in 0.082195 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表