xinghesnak发表于2006-5-13 8:31:00
楼上的,你的数组下标定义的是1到200,而你的n是0,所以越界了。。定义你的数组时用
Dim p(0 To 200) As pointinfo Dim ps(0 To ...
呵呵我是新手多谢指教!太感谢了!
但现在又出现新问题了。(注:我又把程序稍改了下,从p(0)开始记录点)
我想把点集中y最近小且距x最远的点找到,就用二分法排了序,但数组p()的值纵传不到数组pl()上。请在帮忙看下:
Option Explicit Private Type pointinfo x As Single '点的x 坐标值 y As Single '点的y 坐标值 q As Single '与水平线的夹角 End Type Dim p0 As pointinfo Dim p(0 To 200) As pointinfo '点集 Dim pl(0 To 200) As pointinfo '求出起始点 Dim ps(0 To 200) As pointinfo '排序后的点集 Dim pi(0 To 200) As pointinfo '极点 Dim n, m, d As Integer Dim x0, y0 As Single Dim l, e As Integer
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) DrawWidth = 4 If n = 0 Then p(0).x = x p(0).y = y Circle (x, y), 100, RGB(255, 0, 255) Else '输入点集 p(n).x = x p(n).y = y Circle (x, y), 10, RGB(255, 255, 0) End If n = n + 1 x0 = x y0 = y End Sub
Private Sub Command2_Click() Dim i As Integer Dim q As Single p(n).x = x0 p(n).y = y0 Const pi = 3.14 Dim u, j As Integer Dim k, r, f As Integer Dim term As pointinfo For u = 0 To n term = p(l) k = 0 r = u - 0 Do While k <= r f = Int((k + r) / 2) If term.y < pl(f).y Or (term.y = pl(f).y And (Abs(term.x) > Abs(pl(f).x))) Then r = f - 1 Else k = f + 1 End If Loop For j = u - 1 To k Step -1 pl(j + 1) = pl(j) Next j pl(k) = term Next u
|