Private x(), y(), m, n, p(5), q(5), r(5), s(5), u(5), v(5), a, b, c, Pmax, Pmin, Pn As Long
Private Sub text1_change() '输入行数
m = Text1.Text
End Sub
Private Sub text2_change() '输入列数
n = Text2.Text
End Sub
Private Sub command1_click() '输入数据
ReDim x(m, n)
List1.Clear
For i = 1 To m
For j = 1 To n
x(i, j) = InputBox("x(" + CStr(i) + "," + CStr(j) + ")=", "输入读数")
List1.AddItem "x(" + CStr(i) + "," + CStr(j) + ")=" + CStr(x(i, j))
Next j
Next i
End Sub
'找高点,第二高点,低点
Private Sub command2_click()
Pmax = 0
a = 0
For i = 1 To m
For j = 1 To n
If x(i, j) > Pmax Then
Pmax = x(i, j)
p(0) = i
q(0) = j
a = 1
ElseIf x(i, j) = Pmax Then
p(a) = i
q(a) = j
a = a + 1
End If
Next j
Next i
Print Pmax, p(0), q(0), p(1), q(1), p(2), q(2), a '找两个或多个高点
Pn = 0
For i = 1 To m
For j = 1 To n
If x(i, j) <> Pmax Then
If x(i, j) > Pn Then
Pn = x(i, j)
r(0) = i
s(0) = j
b = 1
ElseIf x(i, j) = Pn Then
r(b) = i
s(b) = j
b = b + 1
End If
End If
Next j
Next i
'Print Pn, r(0), s(0), r(1), s(1), r(2), s(2), b '找俩个或多个第二高点
Pmin = x(1, 1)
c = 0
For i = 1 To m
For j = 1 To n
If x(i, j) < Pmin Then
Pmin = x(i, j)
u(0) = i
v(0) = j
c = 1
ElseIf x(i, j) = Pmin Then
u(c) = i
v(c) = j
c = c + 1
End If
Next j
Next i
'Print Pmin, u(0), v(0), u(1), v(1), u(2), v(2), c找两个或多个最小点
'k = (p(0) - u(0)) / (q(0) - v(0))
't = (-1) / k '方程:0=tj-i+p(0)-tq(0)
'd = (t * s(0) - r(0) + p(0) - t * q(0)) / Sqr(t ^ 2 + 1 + (p(0) - t * q(0)) ^ 2)
'Print k, t, d '斜率,轴斜率,第二点到第一点距离
End Sub