标题:各位老师,难题求解
只看楼主
h2918228916
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2019-6-7
结帖率:50%
 问题点数:0 回复次数:0 
各位老师,难题求解
要求编写一个“统计直角三角形的个数”的程序,功能如下:在文本框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’
要求对象
搜索更多相关主题的帖子: If 三角形 代码 Single Then 
2020-02-10 16:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-499176-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.010974 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved