CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: no duplicates

  1. #1
    Join Date
    Apr 2001
    Location
    Chicago, IL
    Posts
    27

    no duplicates

    Using the code below, what code would I have to add in order to ensure that an item is added only one time? (if I already added it to the second list and tried to add it again using the command button, an error msg should pop up) Thank you.

    private Sub cmdAdd_Click()
    Dim i as Integer
    for i = 0 to List1.ListCount - 1
    If List1.Selected(i) = true then List2.AddItem List1.List(i)
    End If
    next
    End Sub

    private Sub Form_Load()
    Dim aLine as string
    Open App.Path & "\grocery.txt" for input as #1 Do While Not EOF(1)
    Line input #1, aLine
    List1.AddItem aLine
    Loop
    Close #1
    End Sub




    Archie Kantzavelos

  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: no duplicates

    The following code should work satisfactorily for a short grocery list.


    private Sub cmdAdd_Click()
    Dim i as Integer, j as integer
    dim Found as boolean
    for i = 0 to List1.ListCount - 1
    If List1.Selected(i) = true then
    found = false
    for j = 0 to List2.ListCount -1
    found = (list2.list(j)=list1.list(i))
    if found then exit for
    next
    if not found then
    List2.AddItem List1.List(i)
    else
    msgbox "error"
    endif
    End If
    next
    End Sub





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