A “for loop” is exiting prematurely.
You can find the loop that is giving me troubles at the line(about half way down):
“For Row = DataRow To Ptr2FDc.count + DataRow”
The debugger gets as far as just before executing the line:
.Cells(Row, ElevationIDColumn).value = Ptr2FDc(Index).ID
The code exits immediately (without executing the above line of code) to the end of the workbook.
I checked the “for” variables. DataRow IS 2 and Ptr2FDc.count IS 20
Index has a valid number of 1
In the debugger I can see the PTR2FDc collection object and it does have an object in the collection at index 1. It is the correct object.
There is no error code
Public Sub PrintFDcollection(ByVal Wrkbk As Workbook, ByVal WrkSht4Printout As Worksheet, ByVal FieldDataCollection As MeasurementCollection)
Dim Ptr2FDc As MeasurementCollection
Dim LabelRow As Long
Dim DataRow As Long
Dim Row As Long
Dim Index As Long
Dim EndRowNum As Long
Const ElevationIDColumn = 1
Const X_CoordinateColumn = 2
Const Y_CoordinateColumn = 3
Const ElevationColumn = 4
Const ElevationTypeColumn = 5
With Wrkbk
With WrkSht4Printout
' Instantiate FieldDataCollection (copy of original) as a pointer
Set Ptr2FDc = FieldDataCollection
' store column labels in FieldDataCollection object
LabelRow = 1
.Cells(LabelRow, ElevationIDColumn).value = Ptr2FDc.IDColumnLabel
.Cells(LabelRow, X_CoordinateColumn).value = Ptr2FDc.X_CoordinateColumnLabel
.Cells(LabelRow, Y_CoordinateColumn).value = Ptr2FDc.Y_CoordinateColumnLabel
.Cells(LabelRow, ElevationColumn).value = Ptr2FDc.ElevationColumnLabel
.Cells(LabelRow, ElevationTypeColumn).value = Ptr2FDc.ElevationTypeColumnLabel
'
' for as many Measurements exist in FieldData
DataRow = 2
EndRowNum = Ptr2FDc.count + DataRow
For Row = DataRow To Ptr2FDc.count + DataRow
' read MeasurementObj data into worksheet
Index = Row - 1
.Cells(Row, ElevationIDColumn).value = Ptr2FDc(Index).ID
.Cells(Row, X_CoordinateColumn).value = Ptr2FDc(Index).Coordinates.X
.Cells(Row, Y_CoordinateColumn).value = Ptr2FDc(Index).Coordinates.Y
.Cells(Row, ElevationColumn).value = Ptr2FDc(Index).Elevation
.Cells(Row, ElevationTypeColumn).value = Ptr2FDc(Index).ElevationType
Next
End With
End With
End Sub
Bookmarks