Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

No Format
Public mymultivalues As New multivalues
Public Sub CreatemultivaluesCollectionSafer()

    mymultivalues.AddFromValues "WH", "Whitehorse", "North"
    mymultivalues.AddFromValues "YW", "YellowKnife", "North"
    mymultivalues.AddFromValues "KL", "Kamloops"

    Dim tempmultivalue As multivalue

    For Each tempmultivalue In mymultivalues.Items
        Debug.Print tempmultivalue.FullName
    Next tempmultivalue

    Dim primkeyToSearch As String
    
    primkeyToSearch = "KL"
    
    Debug.Print "Primary Key = " & primkeyToSearch
    On Error Resume Next ' If Not Found will Throw Error!
    Debug.Print "KeyValOne = " & mymultivalues.Item(primkeyToSearch).keyvalone
    Debug.Print "FullName = " & mymultivalues.Item(primkeyToSearch).FullName
End Sub
Public Sub TestPublicCollections()
    Dim primkeyToSearch As String
    
    primkeyToSearch = "WH"
    Debug.Print "Primary Key = " & primkeyToSearch
    On Error Resume Next ' If Not Found will Throw Error!
    Debug.Print "KeyValOne = " & mymultivalues.Item(primkeyToSearch).keyvalone
    Debug.Print "FullName = " & mymultivalues.Item(primkeyToSearch).FullName
    Debug.Print "Exists Bool = " & mymultivalues.Exists(primkeyToSearch)
End Sub

multivalue.cls:


No Format
Option Explicit

'multivalue Class

Private m_primkey As String
Private m_keyvalone As String
Private m_keyvaltwo As String
Private m_initialized As Boolean

Public Function Init(ByVal primkey_ As String, ByVal keyvalone_ As String, Optional ByVal keyvaltwo_ As String) As Boolean
    If m_initialized Then
        err.Raise 5, TypeName(Me) & ".Init", "Already initialized"
    End If
    If primkey_ = vbNullString Or keyvalone_ = vbNullString Then Exit Function 'Returns False
    
    m_primkey = primkey_
    m_keyvalone = keyvalone_
    m_keyvaltwo = keyvaltwo_
    m_initialized = True
    
    Init = True
End Function

Property Get primkey() As String
    primkey = m_primkey
End Property

Property Get keyvalone() As String
    keyvalone = m_keyvalone
End Property

Property Get keyvaltwo() As String     
    keyvaltwo = m_keyvaltwo
End Property

Property Get FullName() As String
    FullName = m_primkey & " " & m_keyvalone & " " & m_keyvaltwo
End Property

Public Function Self() As multivalue
    Set Self = Me
End Function

...