I declared a sub in the Class module 'vehRows', to allow me to pass arguments, similar to a class constructor in Java or C++
Public Sub InitializeAttributes(sourceVeh_c As String, vehNum_c As String, impFilePrefix_c As String, expFilePrefix_c As String, _
pitGroupPrefix_c As String, pitGroupSuffix_c As String, driver_c As String, descriptionPrefix_c As String, _
classes_c As String, category_c As String, importSheet_ As Worksheet, descriptionDelimeter_c As String)
This is the full Class Module
Public importSheet As Worksheet
Public sourceVeh As String
Public expFilePrefixStr As String
Private pitGroupPrefix As String
Private impFilePrefix As String
Private pitGroupSuffix As String
Private descriptionPrefix As String
Private descriptionDelimeter As String
Private defaultLiveryStr As String
Private vehNumStr As String
Private pitGroupStr As String
Private driverStr As String
Private descriptionStr As String
Private classesStr As String
Private categoryStr As String
'+--------------+-------+--------------------+--------------------+-----------------+-----------------+--------+--------------------+---------+----------+
'| Source veh # | Veh # | Import file Prefix | Export file Prefix | PitGroup Prefix | PitGroup Suffix | Driver | Description Prefix | Classes | Category |
'+--------------+-------+--------------------+--------------------+-----------------+-----------------+--------+--------------------+---------+----------+
'| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
'+--------------+-------+--------------------+--------------------+-----------------+-----------------+--------+--------------------+---------+----------+
'+-----------------------+
'| Attributes of vehFile |
'+-----------------------+
'| DefaultLivery= |
'| Number= |
'| PitGroup= |
'| Driver= |
'| Description= |
'| Classes= |
'| Category= |
'+-----------------------+
'constructor
Private Sub Class_Initialize()
'This sub seems to be pointless
'Me.* is not to be used here
defaultLivery(expFilePrefixStr) = vehNum
pitGroup(pitGroupPrefix) = pitGroupSuffix
description(descriptionPrefix, descriptionDelimeter) = vehNum
End Sub
Public Sub InitializeAttributes(sourceVeh_c As String, vehNum_c As String, impFilePrefix_c As String, expFilePrefix_c As String, _
pitGroupPrefix_c As String, pitGroupSuffix_c As String, driver_c As String, descriptionPrefix_c As String, _
classes_c As String, category_c As String, importSheet_ As Worksheet, descriptionDelimeter_c As String)
Set importSheet = importSheet_c
sourceVeh = sourceVeh_c
impFilePrefix = impFilePrefix_c
expFilePrefixStr = expFilePrefix_c
pitGroupPrefix = pitGroupPrefix_c
pitGroupSuffix = pitGroupSuffix_c
descriptionPrefix = descriptionPrefix_c
descriptionDelimeter = descriptionDelimeter_c
'None of the following come up in Me.* intellisence suggestion
'Me.* is not to be used here
vehNum = vehNum_c
driver = driver_c
classes = classes_c
category = category_c
'It made more sense to place thse in the Class_Initialize() sub, since they format already initialized variables.
'Porential ERROR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'Me.importSheet = importSheet
End Sub
'+-----------------------+
'| Attributes of vehFile |
'+-----------------------+
'| DefaultLivery= |
'| Number= |
'| PitGroup= |
'| Driver= |
'| Description= |
'| Classes= |
'| Category= |
'+-----------------------+
Private Property Let defaultLivery(expFilePrefix_m As String, vehNum_m As String)
defaultLiveryStr = """" & expFilePrefixStr & vehNum & ".DDS"""
End Property
Public Property Get defaultLivery(expFilePrefix_m As String) As String
Let defaultLivery = defaultLiveryStr
End Property
Private Property Let vehNum(vehNum_m As String)
vehNum = vehNum_m
End Property
Public Property Get vehNum() As String
Let vehNum = vehNumStr
End Property
Private Property Let pitGroup(pitGroupPrefix As String, pitGroupSuffix As String)
pitGroupStr = pitGroupPrefix + pitGroupSuffix
If (pitGroupStr = "") Then
pitGroupStr = importSheet.Cells.Find(What:="PitGroup=", LookIn:=xlValues, lookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)
End If
'Let Me.pitGroup = pitGroupStr
End Property
Public Property Get pitGroup(pitGroupPrefix As String) As String
Let pitGroup = pitGroupStr
End Property
Private Property Let driver(driver_m As String)
Let driverStr = driver_m
If (driverStr = "") Then
driverStr = importSheet.Cells.Find(What:="Driver=", LookIn:=xlValues, lookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)
End If
Let Me.pitGroup = pitGroupStr
End Property
Public Property Get driver() As String
Let driver = driverStr
End Property
Private Property Let description(descriptionPrefix_c As String, descriptionDelimeter_c As String, vehNum_c As String)
If (descriptionPrefix_c = "") Then
descriptionPrefix_c = importSheet.Cells.Find(What:="Description=", LookIn:=xlValues, lookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)
'descriptionPrefix_c
'Check if delimiter exists
If InStr(descriptionPrefix_c, descriptionDelimeter_c) <> 0 Then 'extract up to delimiter so we can later assign unique numbers to it
descriptionPrefix_c = Mid(descriptionPrefix_c, 2, InStr(descriptionPrefix_c, descriptionDelimeter_c) - 2) 'Start after ", hence 2
Else 'Start from the right, & try to spot numeric number if possible
Dim isInteger As Boolean
isInteger = False
Dim loopCounter As Integer
Dim booleanTrueCounter As Integer 'If booolean changes back to false, then terminate loop
loopCounter = 0
booleanTrueCounter = 0
Dim descriptionPrefix_MaxLen As Integer
For i = (Len(descriptionPrefix_c) - 1) To 1 Step -1 'Work backwards, before last ", hence Len()-1
isInteger = IsNumeric(Mid(descriptionPrefix_c, i, 1)) 'Might cause LOGICAL ERROR !!!!!!!!!!!!!!!!!!!!!!!
loopCounter = loopCounter + 1
If isInteger = True Then
booleanTrueCounter = booleanTrueCounter + 1
ElseIf isInteger = False And booleanChangeCounter > 0 Then
descriptionPrefix_MaxLen = loopCounter 'may be able to substitute loopCounter with "(Len(descriptionPrefix_c) - 1) - 1"
descriptionPrefix_c = Left(descriptionPrefix_c, Len(descriptionPrefix_c) - loopCounter)
Exit For
' ElseIf isInteger = False And i = 1 Then
' 'No numeric value was found, leave as as is
' descriptionPrefix_c = Mid(descriptionPrefix_c, 2, InStr(descriptionPrefix_c, descriptionDelimeter_c) - 2)
End If
Next i
End If
End If
descriptionStr = descriptionPrefix_c + descriptionDelimeter_c + vehNum
'Let description = descriptionStr
End Property
Public Property Get description(descriptionPrefix_c As String, descriptionDelimeter_c As String) As String
Let description = descriptionStr
End Property
Private Property Let classes(classes_m As String)
classesStr = classes_m
If (classesStr = "") Then
classesStr = importSheet.Cells.Find(What:="Classes=", LookIn:=xlValues, lookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)
End If
End Property
Public Property Get classes() As String
Let classes = classesStr
End Property
Private Property Let category(category_m As String)
If (category_m = "") Then
category_m = importSheet.Cells.Find(What:="Category=", LookIn:=xlValues, lookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)
End If
categoryStr = category_m
End Property
Public Property Get category() As String
Let category = categoryStr
End Property
'+-----------------------+
'| Attributes of vehFile |
'+-----------------------+
'| DefaultLivery= |
'| Number= |
'| PitGroup= |
'| Driver= |
'| Description= |
'| Classes= |
'| Category= |
'+-----------------------+
In the main method/class/function, I have the following statement to pass the information to the class instance, vehRow8
Dim vehRows8 As New vehRows
vehRows8.InitializeAttributes sourceVeh, vehNum, impFilePrefix, expFilePrefix, _
pitGroupPrefix, pitGroupSuffix, driver, descriptionPrefix, _
classes, category, importSheet, descriptionDelimeter
Full error message is,
Run-time error '91':
Object variable or With block variable not set
Bookmarks