×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Dynamic Array doesn't work

Dynamic Array doesn't work

Dynamic Array doesn't work

(OP)
1) a row from a text file is read with the "Line input" command
2) some information is picked up from that row with "Mid" (coordinates X,Y,Z and an index number)
3) index number indicates whether this point is a single point or a part of line,
    so there are to Cases how to continue from this phase
4) if the point is a member of a line, other points (amount is unknown so far) must also be read from the file (=next rows).

So.. X,Y,Z already read from the line must be stored before reading a new row from the file, which contain another coordinates. Then the next row is read and if the index number tells this row is still a part of the same line (if there are rows for lines in the file, there are always at least two points for a line and points for a line are always one row after another row).

After all the points (X,Y,Z) are received, an array should be made of this points (dbl3DPolylineVertices(0 to n) and then draw a line in AutoCAD.

My problem is, that I can't make an array from these points I read from my text file. I have "Subscript out of range" as a value for my dbl3DPolylineVertices(intVertexCounter + n) variables. How does this thing work?

Best regards,

Ravn.


        ' case for a line begins
        Case Else
                                                 
        strCurrentIndexNumber = strIndexNumber

        ' stores the points from the already read row
        dbl3DPolylineVertices(0) = Mid(strLine1, 33, 14)
        dbl3DPolylineVertices(1) = Mid(strLine1, 47, 14)
        dbl3DPolylineVertices(2) = Mid(strLine1, 61, 14)
        
        ' begins a loop, which goes as long as the last row imported from the file has got a different index number
        Do Until strIndexNumber <> strCurrentIndexNumber
            intVertexCounter = 3
            Line Input #1, strLine1
            strBreaklineNumber = LTrim(Mid(strLine1, 9, 8))
            ReDim Preserve dbl3DPolylineVertices(0 To intVertexCounter + 2)
            dbl3DPolylineVertices(intVertexCounter) = Mid(strLine1, 33, 14)
            dbl3DPolylineVertices(intVertexCounter + 1) = Mid(strLine1, 47, 14)
            dbl3DPolylineVertices(intVertexCounter + 2) = Mid(strLine1, 61, 14)
            
           ' changes the intVertexCounter for upcoming coordinates/points
            intVertexCounter = intVertexCounter + 3
        Loop
        
        ' now i know how many vertices there are in my line, so i can define the dimension for array
        ' it was first defined as "Dim dbl3DPolylineVertices() as Double"
        ReDim Preserve dbl3DPolylineVertices(0 To intVertexCounter - 3)
        
        ' SHOULD draw the line in AutoCAD, containing the array made above
        Set ent3DPolyline = ThisDrawing.ModelSpace.Add3DPoly(dbl3DPolylineVertices)

RE: Dynamic Array doesn't work

You need to ReDim before assigning values

Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting

Steam Engine enthusiasts: www.essexsteam.co.uk

RE: Dynamic Array doesn't work

(OP)

Yep! Thanks a lot!

That helped me forward and after that I discovered my initial statement for counter was also misplaced..

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources