湖北国庆节天气:一个vb问题,没懂

来源:百度文库 编辑:高考问答 时间:2024/04/29 07:55:32
给一个三角形的3条边长,计算三角形的面积。编写程序,首先判断给出的3条边能否构成三角形,如可以构成,则计算并该三角形的面积,否则要求重新输入。当输入-1时结束程序
我的答案是:
Private Sub Form_Click()
Dim a, b, c, s As Integer
start:
a = InputBox("请输入三角形的第一条边")
b = InputBox("请输入三角形的第二条边")
c = InputBox("请输入三角形的第三条边")
If a = -1 Or b = -1 Or c = -1 Then End
If (a + b < c) Or (a + c < b) Or (b + c < a) Or (a < 0) Or (b < 0) Or (c < 0) Then
GoTo start
Else: GoTo 100
End If
100

Print a, b, c
End Sub
就是不对啊
请大家侃侃
谢谢

你还是菜鸟吧
一堆bug
你的数据类型还搞不懂呢
inputbox返回的是string呀
a='1' b='2'
a+b='12'拉

正确的如下
Private Sub Form_Click()
Dim a, b, c, s As Double

'Enter A
AA:
a = InputBox("ÇëÊäÈëÈý½ÇÐεĵÚÒ»Ìõ±ß", , 0)

If a = "" Then
Exit Sub
End If

If IsNumeric(a) = False Then
MsgBox ("error,please input an digit")
GoTo AA
End If

If a <= 0 Then
MsgBox ("error,please input an digit over zero")
a = InputBox("ÇëÊäÈëÈý½ÇÐεĵÚÒ»Ìõ±ß")
GoTo AA
End If

a = Val(a)
'Enter B
BB:
b = InputBox("ÇëÊäÈëÈý½ÇÐεĵڶþÌõ±ß", , 0)

If b = "" Then
Exit Sub
End If

If IsNumeric(b) = False Then
MsgBox ("error,please input an digit")
GoTo BB
End If

If b <= 0 Then
MsgBox ("error,please input an digit over zero")
GoTo BB
End If
b = Val(b)

'Enter C
CC:
c = InputBox("ÇëÊäÈëÈý½ÇÐεĵÚÈýÌõ±ß", , 0)

If c = "" Then
Exit Sub
End If

If IsNumeric(c) = False Then
MsgBox ("error,please input an digit")
GoTo CC
End If

If c <= 0 Then
MsgBox ("error,please input an digit over zero")
GoTo CC
End If
c = Val(c)

If (a + b < c) Or (a + c < b) Or (b + c < a) Then
MsgBox ("can not build a triangle")
Exit Sub

Else
Print a, b, c

End If

End Sub

好象没有计算过程啊