Option Strict Off
Option Explicit On
Friend Class clsResult
	
	Private m_collResult As Collection
	Private m_bResult As Boolean
	
	Public Event OnResult()
	Public Event OnNotify(ByVal szNotify As String)
	
	Private Sub Class_Initialize_Renamed()
		m_collResult = New Collection
		m_bResult = False
	End Sub
	Public Sub New()
		MyBase.New()
		Class_Initialize_Renamed()
	End Sub
	
	Private Sub Class_Terminate_Renamed()
		m_collResult = Nothing
	End Sub
	Protected Overrides Sub Finalize()
		Class_Terminate_Renamed()
		MyBase.Finalize()
	End Sub
	
	
	Public Property Result() As Boolean
		Get
			Result = m_bResult
		End Get
		Set(ByVal Value As Boolean)
			m_bResult = Value
		End Set
	End Property
	
	
	Public Property Count() As Integer
		Get
			Count = m_collResult.Count()
		End Get
		Set(ByVal Value As Integer)
			If Value = 0 Then
				m_collResult = Nothing
				m_collResult = New Collection
			End If
		End Set
	End Property
	
	
	Public Property Value(Optional ByVal Index As Object = Nothing) As Object
		Get
            Dim lErrorNo As Integer, mV As Object = Nothing
			On Error GoTo Err_Proc
			If IsNumeric(Index) Then
				Index = Index + 1
				Select Case Index
					Case 1 To m_collResult.Count()
                        mV = m_collResult.Item(CInt(Index))
						If lErrorNo = 450 Then
                            mV = m_collResult.Item(CInt(Index))
						End If
				End Select
			Else
                mV = m_collResult.Item(Index)
				If lErrorNo = 450 Then
                    mV = m_collResult.Item(Index)
				End If
			End If
Err_Exit:
            Return mV
			Exit Property
Err_Proc: 
			If lErrorNo = 0 And Err.Number = 450 Then
				lErrorNo = Err.Number
				Resume Next
			End If
			Debug.Print("clsResult.Value " & Err.Description & "(" & Err.Number & ")")
			Resume Err_Exit
		End Get
		Set(ByVal Value As Object)
			Dim bError As Boolean
			On Error GoTo Err_Proc
			If IsNumeric(Index) Then
				Index = Index + 1
				Select Case Index
					Case 1 To m_collResult.Count()
						m_collResult.Add(Value, CInt(Index))
				End Select
			Else
				m_collResult.Add(Value, Index)
			End If
Err_Exit: 
			Exit Property
Err_Proc: 
			If Err.Number = 457 And bError = False Then
				'This key is already associated with an element of this collection(457)
				bError = True
				If IsNumeric(Index) Then
					m_collResult.Remove(CInt(Index))
				Else
					m_collResult.Remove(Index)
				End If
				Resume 
			End If
			Debug.Print("clsResult.Value " & Err.Description & "(" & Err.Number & ")")
			Resume Err_Exit
		End Set
	End Property
	
	Public Sub RaiseResult()
		RaiseEvent OnResult()
	End Sub
	
	Public Sub RaiseNotify(ByVal szNotify As String)
		RaiseEvent OnNotify(szNotify)
	End Sub
	
	Public Sub AddValue(ByRef vValue As Object, Optional ByVal Index As Object = Nothing)
		On Error GoTo Err_Proc
		If IsNothing(Index) Or IsError(Index) Then
			m_collResult.Add(vValue)
		Else
			m_collResult.Add(vValue, Index)
		End If
Err_Exit: 
		Exit Sub
Err_Proc: 
		Debug.Print("clsResult.Value " & Err.Description & "(" & Err.Number & ")")
		Resume Err_Exit
	End Sub
End Class