各位老师,难题求解
要求编写一个“统计直角三角形的个数”的程序,功能如下:在文本框Text1中依次输入3*N个数表示三角形的边长(用逗号分隔并以逗号结尾),单击“计算”按钮Command1后,程序自动统计直角三角形个数,并输出到标签Label1中。Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer
Dim x1 As Single, x2 As Single, x3 As Single, t As Single
Dim Totald As Integer, v As Single, s As String
s = Text1.Text
k = 0: j = 1: Totald = 0
For i = 1 To Len(s)
If Mid(s, i, 1) = "," Then
v = Val(Mid(s, j, i - j)) '提取三角形边长,保存在变量v中
①
If k Mod 3 = 1 Then
x1 = v
ElseIf k Mod 3 = 2 Then
x2 = v
If x1 < x2 Then t = x1: x1 = x2: x2 = t
Else
x3 = v
If x1 < x3 Then t = x1: x1 = x3: x3 = t
If ② Then Totald = Totald + 1
End If
j = j + 1
End If
Next i
Label1.Caption = "一共构成" + Str(Totald) + " 个直角三角形"
End Sub
(1)请在①②划线处补充合适的代码。
(2)划线代码有误,请改正。
(3)观察程序代码,若正确完成(1)、(2)后,调试过程中出现如下错误提示,可能是程序代码执行到第 行报错。
实时错误‘424’
要求对象