#1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Nov 2009
    Posts
    12
    Rep Power
    0

    How to Remove duplicate values from combo box


    i have written a small code in VBA(autocad), which will list the following information
    F-33
    F-22
    F-20
    P-33
    P-40

    in a combo box with out duplicate like
    F
    P

    but the below code was not working, and i am not able to rectify

    Dim grid_nos_str As String
    grid_nos_str = ThisDrawing.GetVariable("users2")
    grid_nos_list = Split(grid_nos_str, ",")

    Dim i1 As Integer
    i1 = 0
    Do While i1 <= UBound(grid_nos_list)
    cbxGridSeries.AddItem Left(grid_nos_list(i1), 1), i1
    i1 = i1 + 1
    Loop

    Dim i3 As Long, Cnt As Long, j As Long
    Dim sTemp As String
    Cnt = cbxGridSeries.ListCount - 1
    For i3 = 0 To Cnt - 1
    For j = i3 + 1 To Cnt
    If cbxGridSeries.List(i3) = cbxGridSeries.List(j) Then
    cbxGridSeries.RemoveItem (j)
    j = j - 1
    Cnt = Cnt - 1
    Else:
    Exit For
    End If
    Next j
    Next i3
  2. #2
  3. Moderator
    ASP Super Genius (4500 - 4999 posts)

    Join Date
    Apr 2009
    Location
    The Great Land
    Posts
    4,620
    Rep Power
    650
    Might be easier to just not add the duplicate item to the box in the first place. Is your list of data in alphabetical order? If so, write your code to save a prefix to the box only when it is a new value, i.e., not the same as the previous one.
  4. #3
  5. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Nov 2009
    Posts
    12
    Rep Power
    0
    Yes, my data in alphabetical order, and i have tried the same with the following code but it is not working. and i am new to the progrmaming concept.

    Dim grid_nos_str As String
    grid_nos_str = ThisDrawing.GetVariable("users2")
    grid_nos_list = Split(grid_nos_str, ",")

    Dim i1 As Integer
    i1 = 0

    Dim checknew As Boolean
    checknew = False
    Do While i1 <= UBound(grid_nos_list)
    If cbxGridSeries.ListCount <> 0 Then
    For i1 = 0 To cbxGridSeries.ListCount - 1
    If cbxGridSeries.List(i1) = Left(grid_nos_list(i1), 1) Then
    checknew = True
    Exit For
    End If
    Next i1
    End If

    If checknew = False Then
    cbxGridSeries.AddItem Left(grid_nos_list(i1), 1)
    End If
    Loop
  6. #4
  7. Moderator
    ASP Super Genius (4500 - 4999 posts)

    Join Date
    Apr 2009
    Location
    The Great Land
    Posts
    4,620
    Rep Power
    650
    Try:
    Code:
    Dim strPrefix As String
    Dim i As Integer
    Dim grid_nos_list 'not sure if have to declare the array for the Split
    
    grid_nos_list = Split(ThisDrawing.GetVariable("users2"), ",")
    
    i = 0
    strPrefix = Left(grid_nos_list(i), 1)
    cbxGridSeries.AddItem strPrefix
    For i = 1 To Ubound(grid_nos_list) - 1
      If Left(grid_nos_list(i), 1) <> strPrefix Then
         cbxGridSeries.AddItem Left(grid_nos_list(i), 1)
         strPrefix = Left(grid_nos_list(i), 1)
      End If
    Next i

    Comments on this post

    • micky agrees
  8. #5
  9. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Nov 2009
    Posts
    12
    Rep Power
    0
    Thanks lot, it works fine.

Similar Threads

  1. Combo Box values display slowly
    By gwwbjw in forum Microsoft Access Help
    Replies: 4
    Last Post: September 14th, 2005, 05:21 AM
  2. How to: Remove duplicate TITLES but keep a COUNTRY code
    By centrextrainer in forum Development Articles
    Replies: 0
    Last Post: June 15th, 2004, 02:49 PM
  3. Form combo box keeps changing my table values
    By dell9702768 in forum Microsoft Access Help
    Replies: 4
    Last Post: May 6th, 2004, 09:33 AM
  4. DropDown Menu - Stop duplicate values showing
    By Rob21p in forum Microsoft SQL Server
    Replies: 1
    Last Post: May 10th, 2003, 06:36 AM
  5. DropDown Menu - Stop duplicate values showing
    By rsashi in forum ASP Development
    Replies: 5
    Last Post: May 10th, 2003, 02:16 AM

IMN logo majestic logo threadwatch logo seochat tools logo