CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2000
    Posts
    200

    Please help - Error 457 - Index already associated with this item.

    Simple form used to input 2 strings (key & value), to be stored in Dictionary (dictLocations)which is instantiated in Module1. Works fine until user clicks yes in message box, then get Error 457 (duplicate key)???

    Thanks for anyone's help!


    private Sub cmdOK_Click()
    Dim key as string, val as string
    dictLocations.Add tbLocNo, tbLocDesc
    If MsgBox("Add Another Location?", vbYesNo) = vbYes then

    me.Hide
    tbLocNo = ""
    tbLocDesc = ""
    me.Show

    else

    me.Hide
    End If
    Unload.me
    End Sub






  2. #2
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: Please help - Error 457 - Index already associated with this item.

    It sames that the key (tbLocNo) of dictLocations is not unique. I don't know how you get the value of tbLocNo before calling dictLocation.Add, but if it is possible that tbLocNo is duplicate, try to add a suffix to make it unique. For example:

    dictLocation.Add tbLocNo & CStr(intCounter), tbLocDesc



    Regards,

    Michi
    MCSE, MCDBA

  3. #3
    Join Date
    Sep 2000
    Posts
    200

    Re: Please help - Error 457 - Index already associated with this item.

    The FIRST key value is changing anytime tbLocNo changes. I don't understand why, but when the user enters a SECOND key value in the textbox, the FIRST key entry in the dict changes to that value. Thus, when the Add method is called, the key is already in the dictionary. (?)

    Thanks for your help.
    John R.


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

Featured