hi tommy,
why this code not work when i try to run in autocad?
it says run time erro 99
subscript out of range

ive change the path of a txt file.."D:\coordinates.txt"

what will i do? i need this macro that autocad will import txt file coordinates and plot a line in autocad.. anybody can answer this please... thanks in advance

Option Explicit
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
Public Function ReadTxtFile(fil As String) As Collection
Dim fd As Long
Dim sline As String
Dim txtColl As New Collection
fd = FreeFile
Open fil For Input Access Read Shared As fd
Do Until EOF(fd)
Line Input #fd, sline
txtColl.Add sline
Loop
Close fd
Set ReadTxtFile = txtColl
End Function

'~~~~~~~~~~~~~~~~~~~~~~~~~~~'

Sub test()
Dim col As New Collection
Dim itm As Variant
Dim ar() As Variant
Dim i As Integer, j As Integer
Dim iCount As Integer
Set col = ReadTxtFile("C:\Temp\Frame_Profiles.txt") '<-change the full path of the text file
For i = 1 To col.Count Step 2
ReDim Preserve ar(j)
ar(j) = col.Item(i) & col.Item(i + 1)
j = j + 1
Next
iCount = UBound(ar)
Dim match As String
Dim framenum As String
i = 0
Do Until i >= iCount
j = 0
DoNext:
Dim pts() As Double
match = Left(ar(i), InStr(1, ar(i), ",") - 1)
framenum = Left(ar(i), InStr(1, ar(i), ",") - 1)
Do While match = framenum
itm = Split(ar(i), ",")
ReDim Preserve pts(j + 1) As Double
pts(j) = CDbl(itm(1)): pts(j + 1) = CDbl(itm(2))
j = j + 2
i = i + 1
If i >= iCount Then
Exit Do
End If
framenum = Left(ar(i), InStr(1, ar(i), ",") - 1)
If match <> framenum Then
Exit Do
GoTo DoNext
End If
Loop
Dim opline As AcadLWPolyline
Set opline = ThisDrawing.ModelSpace.AddLightWeightPolyline(pts)
Loop
ThisDrawing.Regen acActiveViewport
End Sub