Option Explicit
Option Base 1
' ----------------------------------------------------------------
' Procedure Name: GetFoodItemContentsList
' Purpose: Load a list of Contents for a specific Food Item, as text, into an array.
' Procedure Kind: Function
' Procedure Access: Public
' Parameter piTableRow (Long): Data table row where the Food Item's Contents are listed.
' Parameter poFoodItemsTable (ListObject): Data table where the Food Items are listed.
' Parameter pasList (String): String array to be filled is passed by caller as a ByRef parameter.
' Return Type: String)
' Author: Jim
' Date: 9/27/2023
' ----------------------------------------------------------------
Function GetFoodItemContentsList( _
ByVal piTableRow As Long, _
ByVal poFoodItemsTable As ListObject, _
ByRef pasContentsList() As String)
ReDim pasContentsList(1)
Dim iColumnsCount As Long
Dim iColumn As Long
Dim sCellContent As String
' Get count of columns in the table, less one to account for the first column
' containing the table's "row headers" (i.e., Food Item types/names).
iColumnsCount = poFoodItemsTable.ListColumns.Count - 1
' Iterate through data table columns.
For iColumn = 1 To iColumnsCount
' Get the string value for the name of the individual content item.
sCellContent = poFoodItemsTable.DataBodyRange(piTableRow, iColumn + 1)
' If sCellContent is not empty then put it into the array.
If sCellContent <> "" Then _
ReDim Preserve pasContentsList(iColumn)
pasContentsList(iColumn) = sCellContent
Else
' If sCellContent = "" Then done, return to the caller.
Exit Function
End If
Next iColumn
End Function