Results 1 to 4 of 4

Thread: New to collections

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    7

    Question

    I am trying to load into a collection the key and member from a file. When I run the program I get "Key already associated error" any suggestions on this code?
    Private Sub Form_Load()
    Dim mcollTerms As New Collection
    Dim strTerms As String 'key
    Dim strDefine As String 'member
    Dim j As Integer
    Dim Temp As String
    Me.Top = (Screen.Height - Me.Height) / 2
    Me.Left = (Screen.Width - Me.Width) / 2
    Open "a:\computerTerms.gls" For Input As #1
    Dim obj As Variant
    For Each obj In mcollTerms
    mcollTerms.Remove 1
    Next obj
    Do While Not EOF(1)
    mcollTerms.Add strDefine, strTerms
    lstTerms.AddItem strTerms
    Loop
    lstTerms.ListIndex = 1
    Close #1
    Thanks
    Kelly

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    You forgot you input from your file:

    Do While Not EOF(1)
    Input #1, strDefine, strTerms 'get the stuff from file
    mcollTerms.Add strDefine, strTerms
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    7
    still getting error:
    Open "a:\computerTerms.gls" For Input As #1
    Dim obj As Variant
    For Each obj In mcollTerms
    mcollTerms.Remove 1
    Next obj
    Do While Not EOF(1)
    Input #1, strDefine, strTerms
    mcollTerms.Add strDefine, strTerms ('error here already associated key)
    lstTerms.AddItem strTerms
    Loop
    lstTerms.ListIndex = 1
    Close #1

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    7

    Smile

    thanks HeSaidJoe
    there was some other syntex probs. but got it reading and inputting the file. All I need to do now is code my click event in the list box to pull up the member that goes with the key.
    Thaks agian
    Kelly

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width