请问一下VB中怎样编写当combo. text中选择的内容不同时,后面text运用的公式不同。比如说当combo1.text中为均布荷载时,
 x = Val(Text24.Text) ^ 2 * Val(Text1.Text) / 8 / Val(Text18.Text)
Text2.Text = x
其他情况时
 x = Val(Text1.Text) * Val(Text24.Text) / 4
 Text2.Text = x
直接用if语句这样写显示的类型不匹配。不知道该怎么弄了,求解,谢谢

解决方案 »

  1.   

    写好了,代码如下:Option ExplicitPrivate Sub Command1_Click()
        Dim x As Double
        If Combo1.Text = "均布荷载" Then
            x = Val(Text24.Text) ^ 2 * Val(Text1.Text) / 8 / Val(Text18.Text)
            Text2.Text = x
        Else
             x = Val(Text1.Text) * Val(Text24.Text) / 4
             Text2.Text = x
        End If
    End Sub下载地址:
    链接:https://pan.baidu.com/s/1hc92wB6TaJf-T4t7mTBgHg 
    提取码:exqh 运行示例: