-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCActivity.cls
More file actions
560 lines (474 loc) · 17.2 KB
/
CActivity.cls
File metadata and controls
560 lines (474 loc) · 17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "CActivity"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' ### INTERNAL CLASS INSTANCE VARIABLE DECLARATIONS ###
' ### PROPERTY DECLARATIONS FOR PUBLIC ACCESS VIA GETTERS & SETTERS ###
Private pActivityCode As String
Private pActivityDescription As String
Private pActivityType As String
Private pServiceInterval As String
Private pPlanned As Boolean
Private pServiceVendor As String
Private pOSP As Boolean
Private pOSPLeadtimeOp As String
Private pOSPServiceOp As String
Private pMaintenanceRouting() As Variant
Private pTypeAttribute As String
Private pCause As String
Private pSource As String
Private pShutdownRequired As Boolean
Private pAssetGroup As String
' eAM STATIC READONLY VARIABLES
Private pTemplate As String
Private pInventoryCategorySet As String
' ##ACTIVITY CODE
Public Property Let activityCode(value As String)
pActivityCode = value
End Property
Public Property Get activityCode() As String
activityCode = pActivityCode
End Property
'## ACTIVITY DESCRIPTION
Public Property Get ActivityDescription() As String
If (pPlanned And Me.ActivityType <> "Not Defined") Then
pActivityDescription = ActivityType & " - " & _
pServiceInterval & " Monthly - " & _
Right(pActivityCode, Len(pActivityCode) - WorksheetFunction.Search("-", pActivityCode))
Else
'Manual Activity Description
pActivityDescription = pActivityType & " (Manual)"
End If
ActivityDescription = pActivityDescription
End Property
' ##ACTIVITY TYPE
Public Property Let ActivityType(value As String)
Dim activityTypeValidation As Boolean
Dim validationResult As String
activityTypeValidation = False
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets("Lookups")
Dim lookupColumn As String
Dim lookupColumnBaseCell As String
Dim lookupColumnRange As String
lookupColumn = "F"
lookupColumnRange = lookupColumn & ":" & lookupColumn
lookupListlookupColumnBaseCell = lookupColumn & "2"
Dim rowCount As Integer
rowCount = WorksheetFunction.CountA(wks.Range(lookupColumnRange)) - 1
Dim activitiesList() As String
ReDim activitiesList(rowCount - 1)
For i = 0 To rowCount Step 1
activitiesList(i) = wks.Range(lookupListlookupColumnBaseCell).Offset(i)
If (value = activitiesList(i)) Then activityTypeValidation = True
Next
If (activityTypeValidation) Then
pActivityType = value
Else
validationResult = "Activity Type [ " & value & " ] is not valid. Use one of the following:" & vbNewLine
For i = 0 To rowCount Step 1
validationResult = validationResult & "-" & activitiesList(i) & vbNewLine
Next
pActivityType = InputBox(Prompt:=validationResult, Title:="Activity Type Error")
End If
End Property
Public Property Get ActivityType() As String
Dim typePrefix As String
typePrefix = Left(pActivityCode, 1)
Select Case (typePrefix)
Case "C"
pActivityType = "Calibration"
Case "M"
pActivityType = "Maintenance"
Case "I"
pActivityType = "Inspection"
Case Else
pActivityType = "Not Defined"
End Select
ActivityType = pActivityType
End Property
' ## SERVICE INTERVAL
Public Property Get ServiceInterval() As Integer
If (pActivityCode <> "" And pActivityType <> "Not Defined") Then
pServiceInterval = CInt(Mid(pActivityCode, 2, WorksheetFunction.Search("-", pActivityCode) - 2))
Else
pServiceInterval = 0
End If
ServiceInterval = pServiceInterval
End Property
' ##EXTERNAL VENDOR NAME
Public Property Let ServiceVendor(value As String)
Dim serviceVendorValidation As Boolean
Dim validationResult As String
serviceVendorValidation = False
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets("Lookups")
Dim lookupColumn As String
Dim lookupColumnBaseCell As String
Dim lookupColumnRange As String
lookupColumn = "K"
lookupColumnRange = lookupColumn & ":" & lookupColumn
lookupListlookupColumnBaseCell = lookupColumn & "2"
Dim rowCount As Integer
rowCount = WorksheetFunction.CountA(wks.Range(lookupColumnRange)) - 1
Dim vendorList() As String
ReDim vendorList(rowCount - 1)
For i = 0 To rowCount Step 1
vendorList(i) = wks.Range(lookupListlookupColumnBaseCell).Offset(i)
If (value = vendorList(i)) Then serviceVendorValidation = True
Next
If (serviceVendorValidation) Then
pServiceVendor = value
Else
validationResult = "Vendor [ " & value & " ] is not valid. Use one of the following:" & vbNewLine
For i = 0 To rowCount Step 1
validationResult = validationResult & "-" & vendorList(i) & vbNewLine
Next
pServiceVendor = InputBox(Prompt:=validationResult, Title:="Vendor Error")
End If
pServiceVendor = value
End Property
Public Property Get ServiceVendor() As String
ServiceVendor = pServiceVendor
End Property
' ##OSP ACTIVITY
Public Property Let OSP(value As Boolean)
If (pOSP = "") Then
pOSP = False
Else
pOSP = value
End If
End Property
Public Property Get OSP() As Boolean
If (pServiceVendor <> "") Then pOSP = True
OSP = pOSP
End Property
' ##OSP Leadtime Standard Operation Code
Public Property Let OSPLeadtimeOp(value As String)
If (pOSP) Then
Dim leadtimeOpValidation As Boolean
Dim validationResult As String
leadtimeOpValidation = False
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets("Lookups")
Dim lookupColumn As String
Dim lookupColumnBaseCell As String
Dim lookupColumnRange As String
lookupColumn = "I"
lookupColumnRange = lookupColumn & ":" & lookupColumn
lookupListlookupColumnBaseCell = lookupColumn & "2"
Dim rowCount As Integer
rowCount = WorksheetFunction.CountA(wks.Range(lookupColumnRange)) - 1
Dim leadtimeOpList() As String
ReDim leadtimeOpList(rowCount - 1)
For i = 0 To rowCount Step 1
leadtimeOpList(i) = wks.Range(lookupListlookupColumnBaseCell).Offset(i)
If (value = leadtimeOpList(i)) Then leadtimeOpValidation = True
Next
If (leadtimeOpValidation) Then
pOSPLeadtimeOp = value
Else
validationResult = "Leadtime Operation [ " & value & " ] is not valid. Use one of the following:" & vbNewLine
For i = 0 To rowCount Step 1
validationResult = validationResult & "-" & leadtimeOpList(i) & vbNewLine
Next
pOSPLeadtimeOp = InputBox(Prompt:=validationResult, Title:="Leadtime Operation Error")
End If
Else
pOSPLeadtimeOp = ""
End If
End Property
Public Property Get OSPLeadtimeOp() As String
If (pOSP) Then
Dim leadtimeOpValidation As Boolean
Dim validationResult As String
leadtimeOpValidation = False
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets("Lookups")
Dim lookupColumn As String
Dim lookupColumnBaseCell As String
Dim lookupColumnRange As String
lookupColumn = "I"
lookupColumnRange = lookupColumn & ":" & lookupColumn
lookupListlookupColumnBaseCell = lookupColumn & "2"
Dim rowCount As Integer
rowCount = WorksheetFunction.CountA(wks.Range(lookupColumnRange)) - 1
Dim leadtimeOpList() As String
ReDim leadtimeOpList(0, 1)
For i = 0 To rowCount Step 1
If (Left(wks.Range(lookupListlookupColumnBaseCell).Offset(i), 1) = "L") Then
ReDim Preserve leadtimeOpList(i, 1)
leadtimeOpList(i, 0) = wks.Range(lookupListlookupColumnBaseCell).Offset(i, 0)
leadtimeOpList(i, 1) = wks.Range(lookupListlookupColumnBaseCell).Offset(i, 1)
End If
Next
Dim tempOp As String
For i = 0 To UBound(leadtimeOpList, 1) Step 1
tempOp = Right(leadtimeOpList(i, 1), Len(leadtimeOpList(i, 1)) - WorksheetFunction.Search("-", leadtimeOpList(i, 1)))
If (pServiceVendor = tempOp) Then
leadtimeOpValidation = True
pOSPLeadtimeOp = leadtimeOpList(i, 1)
End If
Next
If (leadtimeOpValidation) Then
pOSPLeadtimeOp = value
Else
validationResult = "Leadtime Operation [ " & value & " ] is not valid. Use one of the following:" & vbNewLine
For i = 0 To rowCount Step 1
validationResult = validationResult & "-" & leadtimeOpList(i) & vbNewLine
Next
pOSPLeadtimeOp = InputBox(Prompt:=validationResult, Title:="Leadtime Operation Error")
End If
Else
pOSPLeadtimeOp = ""
End If
End Property
' ##OSP Service Standard Operation Code
Public Property Let OSPserviceOp(value As String)
If (pOSP) Then
pOSPServiceOp = value
Else
pOSPServiceOp = ""
End Property
Public Property Get OSPserviceOp() As String
If (pOSP) Then
Dim serviceOpValidation As Boolean
Dim validationResult As String
serviceOpValidation = False
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets("Lookups")
Dim lookupColumn As String
Dim lookupColumnBaseCell As String
Dim lookupColumnRange As String
lookupColumn = "I"
lookupColumnRange = lookupColumn & ":" & lookupColumn
lookupListlookupColumnBaseCell = lookupColumn & "2"
Dim rowCount As Integer
rowCount = WorksheetFunction.CountA(wks.Range(lookupColumnRange)) - 1
Dim serviceOpList() As String
ReDim serviceOpList(0, 1)
For i = 0 To rowCount Step 1
If (Left(wks.Range(lookupListlookupColumnBaseCell).Offset(i), 1) = Left(pActivityType, 1)) Then
ReDim Preserve serviceOpList(i, 1)
serviceOpList(i, 0) = wks.Range(lookupListlookupColumnBaseCell).Offset(i, 0)
serviceOpList(i, 1) = wks.Range(lookupListlookupColumnBaseCell).Offset(i, 1)
End If
Next
Dim tempOp As String
For i = 0 To UBound(serviceOpList, 1) Step 1
tempOp = Right(serviceOpList(i, 1), Len(serviceOpList(i, 1)) - WorksheetFunction.Search("-", serviceOpList(i, 1)))
If (pServiceVendor = tempOp) Then
serviceOpValidation = True
pOSPServiceOp = serviceOpList(i, 1)
End If
Next
If (serviceOpValidation) Then
pOSPServiceOp = value
Else
validationResult = "Service Operation [ " & value & " ] is not valid. Use one of the following:" & vbNewLine
For i = 0 To rowCount Step 1
validationResult = validationResult & "-" & serviceOpList(i) & vbNewLine
Next
pOSPServiceOp = InputBox(Prompt:=validationResult, Title:="Serivce Operation Error")
End If
Else
pOSPServiceOp = ""
End If
OSPserviceOp = pOSPServiceOp
End Property
' ##Maintenance Routings - OP-10, 20, 30 -> STD-OPERATION CODE
Public Property Get MaintenanceRouting() As Variant
If (OSP) Then
ReDim pMaintenanceRouting(2, 1)
Else
ReDim pMaintenanceRouting(0, 1)
End If
For i = 0 To UBound(pMaintenanceRouting, 1)
pMaintenanceRouting(i, 0) = CInt(i + 1 & 0)
Next
If (Not (pOSP)) Then
Select Case (pActivityType)
Case "Calibration"
pMaintenanceRouting(0, 1) = "CAL"
Case "Maintenance"
pMaintenanceRouting(0, 1) = "MNT"
Case "Inspection"
pMaintenanceRouting(0, 1) = "INS"
End Select
Else
For i = 0 To UBound(pMaintenanceRouting, 1)
Select Case (pMaintenanceRouting(i, 0))
Case 10
pMaintenanceRouting(i, 1) = pOSPLeadtimeOp
Case 20
pMaintenanceRouting(i, 1) = pOSPServiceOp
Case 30
pMaintenanceRouting(i, 1) = pOSPLeadtimeOp
Select Case (pActivityType)
Case "Calibration"
pMaintenanceRouting(0, 1) = "CAL"
Case "Maintenance"
pMaintenanceRouting(0, 1) = "MNT"
Case "Inspection"
pMaintenanceRouting(0, 1) = "INS"
End Select
End Select
Next
End If
MaintenanceRouting = pMaintenanceRouting
End Property
' ##Activity attribute - TYPE ATTRIBUTE
Public Property Let TypeAttribute(value As String)
pOSPServiceOp = value
End Property
Public Property Get TypeAttribute() As String
TypeAttribute = pTypeAttribute
End Property
' ##Activity attribute - CAUSE
Public Property Let Cause(value As String)
Dim causeValidation As Boolean
Dim validationResult As String
causeValidation = False
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets("Lookups")
Dim lookupColumn As String
Dim lookupColumnBaseCell As String
Dim lookupColumnRange As String
lookupColumn = "G"
lookupColumnRange = lookupColumn & ":" & lookupColumn
lookupListlookupColumnBaseCell = lookupColumn & "2"
Dim rowCount As Integer
rowCount = WorksheetFunction.CountA(wks.Range(lookupColumnRange)) - 1
Dim causeList() As String
ReDim causeList(rowCount - 1)
For i = 0 To rowCount Step 1
causeList(i) = wks.Range(lookupListlookupColumnBaseCell).Offset(i)
If (value = causeList(i)) Then causeValidation = True
Next
If (causeValidation) Then
pCause = value
Else
validationResult = "Activity Cause [ " & value & " ] is not valid. Use one of the following:" & vbNewLine
For i = 0 To rowCount Step 1
validationResult = validationResult & "-" & causeList(i) & vbNewLine
Next
pCause = InputBox(Prompt:=validationResult, Title:="Activity Cause Error")
End If
pCause = value
End Property
Public Property Get Cause() As String
Select Case (pActivityType)
Case "Calibration", "Inspection"
pCause = "Quality and Regulatory"
Case "Maintenance"
pCause = "Equipment"
Case Else
pCause = "Not Defined"
End Select
Cause = pCause
End Property
' ##Activity attribute - SOURCE
Public Property Let Source(value As String)
Dim sourceValidation As Boolean
Dim validationResult As String
sourceValidation = False
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets("Lookups")
Dim lookupColumn As String
Dim lookupColumnBaseCell As String
Dim lookupColumnRange As String
lookupColumn = "K"
lookupColumnRange = lookupColumn & ":" & lookupColumn
lookupListlookupColumnBaseCell = lookupColumn & "2"
Dim rowCount As Integer
rowCount = WorksheetFunction.CountA(wks.Range(lookupColumnRange)) - 1
Dim sourceList() As String
ReDim sourceList(rowCount - 1)
For i = 0 To rowCount Step 1
sourceList(i) = wks.Range(lookupListlookupColumnBaseCell).Offset(i)
If (value = sourceList(i)) Then sourceValidation = True
Next
If (sourceValidation) Then
pSource = value
Else
validationResult = "Activity Source [ " & value & " ] is not valid. Use one of the following:" & vbNewLine
For i = 0 To rowCount Step 1
validationResult = validationResult & "-" & sourceList(i) & vbNewLine
Next
pSource = InputBox(Prompt:=validationResult, Title:="Activity Source Error")
End If
End Property
Public Property Get Source() As String
Select Case (pActivityType)
Case "Calibration"
pSource = "Calibration"
Case "Maintenance"
pSource = "Equipment"
Case "Inspection"
pSource = "Quality & Regulatory"
Case Else
pSource = "Not Defined"
End Select
Source = pSource
End Property
' ##Activity attribute - SHUTDOWN
Public Property Let ShutdownRequired(value As Boolean)
If (value) Then
pShutdownRequired = True
Else
pShutdownRequired = False
End If
End Property
Public Property Get ShutdownRequired() As Boolean
If (pShutdownRequired) Then
pShutdownRequired = True
Else
pShutdownRequired = False
End If
ShutdownRequired = pShutdownRequired
End Property
' ## EAM READONLY PROPERTIES: Item Template
Public Property Get Template() As String
pTemplate = "1:eAM Activities"
Template = pTemplate
End Property
' ## EAM READONLY PROPERTIES: Item Category Set
Public Property Get InventoryCategorySet() As String
pInventoryCategorySet = "EAM.ACTIVITY.EAM"
InventoryCategorySet = pInventoryCategorySet
End Property
' ## EAM READONLY PROPERTIES: Planned
Public Property Get Planned() As String
If (Left(pActivityCode, 3) = "MA-") Then
pPlanned = False
Else
pPlanned = True
End If
Planned = pPlanned
End Property
Public Property Get AssetGroup() As String
If (pActivityType <> "Not Defined") Then
pAssetGroup = Mid(pActivityCode, WorksheetFunction.Search("-", pActivityCode) + 1, Len(pActivityCode))
Else
pAssetGroup = "Not Defined"
End If
AssetGroup = pAssetGroup
End Property
' ## PUBLIC CLASS FUNCTIONS
Function initialiseActivityWithActivityCode(code As String) As CActivity
If (code = "<new activity>") Then
theResult = InputBox("Enter an Activity Code:", "Create a new Activity: Enter new Code")
code = theResult
End If
Me.activityCode = code
End Function
Private Sub Class_Initialize()
pShutdownRequired = True
pOSP = False
pPlanned = True
End Sub