I'm trying to teach myself how to use vba class module. Here's my class module (named clsWorkingRange). Here's the module:
Option Explicit
Private pSheetName As String
Private pColNum As Integer
Public Property Get SheetName() As String
SheetName = pSheetName
End Property
Public Property Let SheetName(SheetName As String)
pSheetName = SheetName
End Property
Public Property Get ColNum() As Integer
ColNum = pColNum
End Property
Public Property Let ColNum(ColNumb As Integer)
pColNum = ColNum
End Property
Public Function Get_Rows_Generic(work_sheet_get As String, column_num As Integer)
'worksheet is the name of a sheet in the form of a string
Dim ws As Worksheet: Set ws = Worksheets(work_sheet_get)
Dim rows_count As Long: rows_count = ws.Cells(rows.Count, column_num).End(xlUp).Row
Get_Rows_Generic = rows_count
End Function
I'm trying to sue the class here (in a separate module):
Option Explicit
Sub test_the_class()
Dim first_class_example As New clsWorkingRange
first_class_example.SheetName = "agentsFullOutput.csv"
first_class_example.ColNum = 1
Debug.Print first_class_example.SheetName
Debug.Print first_class_example.ColNum
Dim row_count_test As Long
row_count_test = first_class_example.Get_Rows_Generic(first_class_example.SheetName, first_class_example.ColNum)
MsgBox "row count is " & row_count_test
End Sub
Debug.Print first_class_example.ColNum prints 0. Why isn't the property coming through as 1?