Hey, I've some subscript out of range error in my coding.
Can anyone help? or explain why?

Code:
Option Explicit
Option Base 1

Private Type Map_UDT1
    Rec As Long
    Pts As Long
End Type
Private MapInfo As Map_UDT1

Private Type Map_POINT
    x As Single
    y As Single
End Type

Private Type Map_UDT2
    Data() As Map_POINT
End Type
Private MapPoint As Map_UDT2

Private Sub SaveFile()
    Dim i As Long
    Dim p As Long

    If Dir(App.Path & "\map.tbl") <> "" Then Kill App.Path & "\map.tbl"
    If Dir(App.Path & "\map.dat") <> "" Then Kill App.Path & "\map.dat"

    For i = 1 to 10
        MapInfo.Rec = i
        MapInfo.Pts = Int(Rnd * 10) + 1
 
        'Save data into the Reference file
        Open App.Path & "\map.tbl" For Binary As #1 Len = Len(MapInfo)
            Put #1, LOF(1) + 1, MapInfo
        Close #1

        ReDim MapPoint.Data(MapInfo.Pts)
        Randomize Timer
        For p = 1 To MapInfo.Pts
            MapPoint.Data(p).x = (Rnd * 101) + 100
            MapPoint.Data(p).y = (Rnd * 3.1) + 3
        Next
    
        'Save data into the points data file
        Open App.Path & "\map.dat" For Binary As #1 Len = Len(MapPoint)
            Put #1, LOF(1) + 1, MapPoint
        Close #1
    Next    
End Sub

Private Sub ReadFile()
Dim Ptr1 As Long
Dim Ptr2
Dim p As Long
Dim str As String

If Dir(App.Path & "\map.tbl") = "" Then
    MsgBox "Missing table file."
    Exit Sub
End If

If Dir(App.Path & "\map.dat") = "" Then
    MsgBox "Missing data file."
    Exit Sub
End If

Ptr1 = 1
Ptr2 = 1
Open App.Path & "\map.tbl" For Binary As #1 Len = Len(MapInfo)
    While Not EOF(1)
        Get #1, Ptr1, MapInfo

        If MapInfo.Pts > 0 Then
            ReDim MapPoint.Data(MapInfo.Pts)
            Open App.Path & "\map.dat" For Binary As #2 Len = Len(MapPoint)
                Get #1, Ptr2, MapPoint
            Close #2
            
            'Update File Pointer
            Ptr2 = (Len(MapPoint) * Ptr2) + 1
            
            For p = 1 To MapInfo.Pts
                'Why I hit the Subscript Out Of Range Error over here?
                'I did declare the MapPoint.Data array before I open the file.
                str = str & MapPoint.Data(p).x & ", " & MapPoint.Data(p).y & vbCrLf
            Next
        End If
        
        Debug.Print str

        'Update File Pointer
        Ptr1 = (Len(MapInfo) * MapInfo.Rec) + 1
    Wend
Close #1
End Sub

[Edited by Chris on 01-17-2001 at 02:57 AM]