dance 发表于 2006-5-12 15:51:00

[求助]拜请各位大虾有关下标越界的问题!!!感激涕零

<P>我在编一个求点集凸包的程序</P>
<P>采点集的程序部分已经搞定了但到了去极点部分就老提示下标越界</P>
<P>下面是我的程序:</P>
<P>Option Explicit<BR>Private Type pointinfo<BR>x As Single&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '点的x 坐标值<BR>y As Single&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '点的y 坐标值<BR>q As Single&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '与水平线的夹角<BR>End Type<BR>Dim p0 As pointinfo<BR>Dim p(1 To 200) As pointinfo&nbsp;&nbsp;&nbsp; '点集<BR>Dim ps(1 To 200) As pointinfo&nbsp;&nbsp;&nbsp; '排序后的点集<BR>Dim pi(1 To 200) As pointinfo&nbsp;&nbsp; '极点<BR>Dim n, m, d As Integer<BR>Dim x0, y0 As Single<BR>Dim l, e As Integer</P>
<P>Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)<BR>DrawWidth = 4<BR>If n = 0 Then<BR>&nbsp;p0.x = x<BR>&nbsp;p0.y = y<BR>&nbsp;Circle (x, y), 100, RGB(255, 0, 255)<BR>Else '输入点集<BR>&nbsp;p(n).x = x<BR>&nbsp;p(n).y = y<BR>&nbsp;Circle (x, y), 10, RGB(255, 255, 0)<BR>End If<BR>n = n + 1<BR>x0 = x<BR>y0 = y</P>
<P>End Sub</P>
<P><BR>Private Sub Command2_Click()<BR>Dim i As Integer<BR>Dim q As Single<BR>p(n).x = x0<BR>p(n).y = y0<BR>Const pi = 3.14<BR>For i = l To n<BR>If p(i).y - p0.y = 0 Then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (总是在这句提示下标越界)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If p(i).x - p0.x = 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p(i).q = 90<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ElseIf p(i).x - p0.x &gt; 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p(i).q = 180 / pi * Atn((p(i).y - p0.y) / (p(i).x - p0.x))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p(i).q = 180 / pi * Atn((p(i).y - p0.y) / (p(i).x - p0.x)) + 180<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>ElseIf p(i).y - p0.y &lt; 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If p(i).x - p0.x = 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p(i).q = 270<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ElseIf p(i).x - p0.x &gt; 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p(i).q = 360 + 180 / pi * Atn((p(i).y - p0.y) / (p(i).x - p0.x))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p(i).q = 180 + 180 / pi * Atn((p(i).y - p0.y) / (p(i).x - p0.x))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>Next i</P>
<P>End Sub</P>

dance 发表于 2006-5-12 22:29:00

[原创]

<P>请各位高手帮忙啊</P>
<P>救命</P>

mccad 发表于 2006-5-13 05:55:00

在Command2_Click中,n值是多少,在哪里确定?

dance 发表于 2006-5-13 14:28:00

mccad发表于2006-5-13 5:55:00static/image/common/back.gif在Command2_Click中,n值是多少,在哪里确定?


<P>随机的</P>
<P>在点击之前点个点多少点n为多少</P>
<P>上限为200</P>

dance 发表于 2006-5-14 22:26:00

[求助]

mccad发表于2006-5-13 5:55:00static/image/common/back.gif在Command2_Click中,n值是多少,在哪里确定?


<P><BR>这个问题已经解决了</P>
<P>还是要感谢你的热心帮忙</P>
页: [1]
查看完整版本: [求助]拜请各位大虾有关下标越界的问题!!!感激涕零