编写VB程序,实现上述功能。运行程序,在列表框List1中显示20个监测点的高度(赛段最高点和最低点分别为第1个和第20个监测点)。在文本框Text1中输入设置障碍间距值,单击“设置”按钮Command1,在标签Label5中显示最多设置障碍物数量,若赛道中不含有相对平缓赛段,则在标签Label5中显示0。程序运行界面如图所示。
Const n=20
Dim a(1 To 2*n) As Integer
Private Sub Form_Load()
'在数据库中读取20个监测点名称和其高度值在List1中显示。读取监测点高度值和每个监测点距赛道起点的距离值,存入数组a,其中a(1)、a(3)、a(5)…a(2*i-1)存储监测点高度值,a(2)、a(4)、a(6)…a(2*i)存储每个监测点距赛道起点的距离值,代码略
End Sub
Private Sub Command1_Click()
Dim i As Single, cnt As Integer, p As Integer
Dim max As Integer, s As Integer
s=Val(text1.Text)
smax=0
For i=1 To n
cnt=1
Do While
cnt=cnt+1
Loop
If cnt-1 >=3 And cnt-1 > max Then
max=cnt-1
End If
Next i
i=smax
If i=0 Then
Label5.Caption=″0″
Else
p=0
Do While i >=s
p=p+1
i=i / (p+1)
Loop
Label5.Caption=Str(p-1)
End If
End Sub
Function judge(x As Integer, y As Integer) As Boolean
judge=False
jmin=x: jmax=x
For m=
If a(2*m-1) < a(2*jmin-1) Then jmin=m
If a(2*m-1) > a(2*jmax-1) Then jmax=m
Next m
If a(2*jmax-1)-a(2*jmin-1) <=20 Then judge=True
End Function