代码如下:
Private Sub Command1_Click()
Dim X As Single, Y As Single, z As Single
Dim r As Double
Dim rmax As Double
Dim rmin As Double
Dim p As Double
X = Val(Text1.Text)
Y = Val(Text2.Text)
z = Val(Text3.Text)
If (Combo1.Text = "1600KVA以上的变压器") Or (Combo1.Text = "1600 KVA以下的变压器") Then
If IsNumeric(Text1.Text) And IsNumeric(Text2.Text) And IsNumeric(Text3.Text) Then
If X < Y Then
t = X
X = Y
Y = t
End If
If X < z Then
t = X
X = z
z = t
End If
If Y < z Then
t = Y
Y = z
z = t
End If
Else
MsgBox "请输入数值"
End If
rmax = Str(X)
rmin = Str(z)
If X + Y + z <> 0 Then '验证有效性
p = (X + Y + z) / 3
r = (rmax - rmin) / p
Text4.Text = r
End If
Else
MsgBox "请选择变压器容量"
End If
If (Combo1.Text = "1600KVA以上的变压器") And (r < 20) Then
Label6.Caption = "合格"
Else
Label6.Caption = "不合格"
End If
If (Combo1.Text = "1600KVA以下的变压器") And (r > 20) Then
Label6.Caption = "合格"
Else
Label6.Caption = "不合格"
End If
End Sub
Private Sub Form_Load()
Combo1.AddItem "1600KVA以上的变压器"
Combo1.AddItem "1600 KVA以下的变压器"
End Sub
问题:Label6.Caption这里显示不对,这段代码是不是放错位置了?或是嵌套进前面那些代码里?该怎么改?谢谢!
參考答案:错误有两个地方,先说Form_Load里面1600 KVA以下的变压器多了个空格
第二个问题
If (Combo1.Text = "1600KVA以上的变压器") And (r < 20) Then
Label6.Caption = "合格"
Else
Label6.Caption = "不合格"
End If
If (Combo1.Text = "1600KVA以下的变压器") And (r > 20) Then
Label6.Caption = "合格"
Else
Label6.Caption = "不合格"
End If
当程序判断第一个条件的时候,虽然你选择了“1600KVA以上的变压器”也r<20的时候,Label6显示是合格,但程序没有停止,依然往下运行,所以才会导致显示不对,,你把这段改成一下的就可以了
If (Combo1.Text = "1600KVA以上的变压器") And (r < 20) Then
Label6.Caption = "合格"
Exit Sub
Else
Label6.Caption = "不合格"
Exit Sub
End If
If (Combo1.Text = "1600KVA以下的变压器") And (r > 20) Then
Label6.Caption = "合格"
Exit Sub
Else
Label6.Caption = "不合格"
Exit Sub
End If