使用变量in和if:下标超出范围 [英] use of variant in and if: subscript out of range

查看:58
本文介绍了使用变量in和if:下标超出范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个程序(它必须找到行之间的交叉点,然后从一个点到另一个点绘制一个段)并且代码位于下面。

hi i'm working on a program (It has to find intersections between lines and then draw a segment from one point to the other) and the code stands underneath.

现在发生的情况是,如果搜索交叉点找到1点,则变量(例如pnt)将被重新标记为pnt(0到2),其中pnt(0)= x pnt(1)= y和pnt(2) = z

如果搜索找到与其相交的2个点,则将变量重新设为pnt(0到5)。因此,程序永远不会知道在折线或样条曲线上找到多少个点。所以我认为:当它只发现1点pnt(3)时,pnt(4)和pnt(5)将不会被分配,所以如果
pnt(3)<> vartype(1)(也尝试了vartype(0)和vartype(10))它找到了2分。但它不起作用。

Now what happens is, if the search for intersection finds 1 point the variant (for instance pnt) wil be redimed as pnt(0 to 2) in which pnt(0)=x pnt(1)=y and pnt(2)=z
If the search finds 2 points that intersect it redim the variant as pnt(0 to 5). So the program never knows how many points found on the polyline or on the spline. So I thougt this: when it only finds 1 point pnt(3),pnt(4) and pnt(5) won't be assigned so if pnt(3)<>vartype(1) (also tried vartype(0) and vartype(10)) it has found 2 points. But it doesn't work.

 

'哪种交叉点:1)与折线交叉2倍,2)与折线交叉1倍带花键的1X,带花键的2x和
    '无限长线和折线的交点

    Dim pnt As Variant

    pnt = polyObj.IntersectWith(XlineObj,acExtendNone)'两者之间的交叉点(1或2点)的合作伙伴

'which kind of intersections: 1) 2x intersections with the polyline, 2) 1x with polyline and 1X with spline, 3) 2x with the spline
    ' intersection from an infinite line and the polyline
    Dim pnt As Variant
    pnt = polyObj.IntersectWith(XlineObj, acExtendNone) 'the coördinates of the intersections between the two (either 1 or 2 points)

   '无限线与样条线的交点

    Dim pnt2 As Variant

   'intersection from an infinite line and the spline
    Dim pnt2 As Variant

    pnt2 = splineObj.IntersectWith(XlineObj,acExtendNone)两者之间的交叉点(1或2点)的合作伙伴关系($ 1 b $ b   

   如果VarType(pnt(2))<> 10和VarType(pnt(5))<> 10如果pnt(5)不存在(或者换句话说只找到1个交叉点时)'下标超出范围)

   

    '1)

        '绘制细分市场$
   

   否则

   如果VarType(pnt(2))<> 10和VarType(pnt2(2))<> 10然后

       

    '2)

        '画出该段

   

   否则

   如果VarType(pnt2(2))<> 10和VarType(pnt2(5))<> 10然后

   

    '3)

        '绘制该段

    pnt2 = splineObj.IntersectWith(XlineObj, acExtendNone)the coördinates of the intersections between the two (either 1 or 2 points)
   
    If VarType(pnt(2)) <> 10 And VarType(pnt(5)) <> 10 Then 'subscript out of range if pnt(5) doesn't exist (or in other words when only 1 intersection is found)
   
    '1)
        'draw the segment
   
    Else
    If VarType(pnt(2)) <> 10 And VarType(pnt2(2)) <> 10 Then
       
    '2)
        'draw that segment
   
    Else
    If VarType(pnt2(2)) <> 10 And VarType(pnt2(5)) <> 10 Then
   
    '3)
        'draw that segment



  &NBSP;其他  

   

        msg = MsgBox("出错了","vbOKOnly","错误"))
   

   结束如果是
   结束如果是
   结束如果


    Else   
   
        msg = MsgBox("something went wrong", vbOKOnly, "error")
   
    End If
    End If
    End If

那么一般情况下,只要变量的大小从0到5,程序就会起作用,但情况并非总是如此。所以我怎么告诉VB,如果第二点不存在,他必须继续前进并检查其他选项是否为
avaible。

So what happens in general is that the program works as long as the variants are dimensioned from 0 to 5, but that isn't always the case. so how do I tell VB that if the second point does not exist he has to move on and check the if the other options are avaible.

 

我坚持这个,我搜索了很多个小时但在隧道尽头看不到光。

I'm stuck on this one, I search for many hours but can't see light at the end of the tunnel.

任何帮助都会非常感激

 

thx提前

 

Wouter

推荐答案

问题解决了,只是偶然发现了ubound函数..现在我正好解决了这个问题:

problem solved, just stumbled upon the ubound function.. works now I just solved it like this:

 

如果UBound(pnt)= 5那么

If UBound(pnt) = 5 Then


这篇关于使用变量in和if:下标超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆