注册 登录
编程论坛 VB6论坛

vb新手上路 有个编程问题求指教 谢谢!

cantmia 发布于 2013-11-10 10:33, 377 次点击
做的一个关于天气的编程 样子我截了个图在附件, 内容是这样的:
        Dim color, mode As String
        color = txtColor.Text
        mode = txtMode.Text
        Select Case color And mode
            Case "Blue" And "S"
                lblForecast.Text = "CLEAR VIEW"
            Case "Blue" And "F"
                lblForecast.Text = "CLOUDS DUE"
            Case color = "Red" And "S"
                lblForecast.Text = "RAIN AHEAD"
            Case Else
                lblForecast.Text = "SNOW INSTEAD"
        End Select
就是你输入color和mode 再点击Describe position
会相应显示
Steady blue, clear view.
Flashing blue, clouds due.
Steady red, rain ahead.
Flashing red, snow instead.
但是我这个就会运行不了,请教大神们帮我修改下呗,多谢!!!
1 回复
#2
风吹过b2013-11-10 16:04
Select  只能对一个 变量 进行多分支选择。

如果你的二个以上的变量,要么事先判断一下,要么你组合判断。

你的代码里,分为四种情况,
分别是 : Blue 里包括两种情况,
          Red 包括一种情况
          其余的是第四种情况。

那么先按 color 判断,然后再判断其它情况。使用 IF 块及IF 嵌套。
if color ="Blue" and (mode ="S" or mode ="F") then             '为boue 时,如果 mode 为S 或F ,分两种提示
    if mode ="S" then                                          'S 时,提示
        lblForecast.Text = "CLEAR VIEW"
    else                                                       '否则提示
        lblForecast.Text = "CLOUDS DUE"
    end if
elseif color ="Red" and mode ="S" then                         '为Red时,如果 mode 为S ,则提示
    lblForecast.Text = "RAIN AHEAD"
else                                                           '以上都不成立时,提示
    lblForecast.Text = "SNOW INSTEAD"
end if
1