請問一下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陳述句這樣寫顯示的型別不匹配。不知道該怎么弄了,求解,謝謝
uj5u.com熱心網友回復:
寫好了,代碼如下:
Option Explicit
Private 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
運行示例:

uj5u.com熱心網友回復:
嗯嗯嗯,非常感謝!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/20003.html
標籤:VB基礎類
