고객 개체 외에 고객 키를 키로 사용하여 모든 고객 개체에 대한 참조를 Dictionary
에 보관하십시오. 새 Customer 객체를 만들 때 먼저 새 CustomerKey가 사전에 이미 있는지 테스트합니다.이 경우 새 객체 만들기를 건너 뛰고 사용자에게 메시지를 표시합니다.
사전을 사용하면 MS Scripting Runtime
에 대한 참조를 추가해야합니다.
이 방법의 다른 장점은 당신이 항상
gDicCustomers(CustomerKey)
어떤 고객 객체를 참조 할 수 있다는 것입니다
Global gDicCustomers as Dictionary
LoadCustomers()
Set gDicCustomers = New Dictionary
For each worksheet in the workbook
If the worksheet contains a named range, "CustomerKey"
If gDicCustomers.Exists(CustomerKey) Then
MsgBox "Dont screw with the customer worksheets - or at least be so decent to change the customer key, too!"
Else
Create a new customer object
Set its key equal to the value in the range "CustomerKey"
Load data from the worksheet into the object
gDicCustomers.Add CustomerKey, CustomerObject
End If
End If
Loop
End
...
적절한 오류 처리 : 그런 다음 의사 코드는이를 원하십니까? –