×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Remove non-consecutive duplicates from combobox

Remove non-consecutive duplicates from combobox

Remove non-consecutive duplicates from combobox

(OP)
i know how to remove duplicates from consecutive list in a combobox.
rent
rent
rent
count
count

CODE

Dim varI As Integer
Dim strTemp As String
Do While varI <= cmbCategory.ListCount
If varI = cmbCategory.ListCount Then
Exit Sub
End If
If strTemp = cmbCategory.List(varI) Then
cmbCategory.RemoveItem (varI)
intK = intK + 1
Else
strTemp = cmbCategory.List(varI)
varI = varI + 1

End If
Loop


How do you remove duplicates that are not consecutive?
rent
count
rent
rent
count
count
the above code only removes the two consecutive values
leaving
rent
count
rent
count
I want it to leave
rent
count

RE: Remove non-consecutive duplicates from combobox

How is the combo box being loaded initially?

RE: Remove non-consecutive duplicates from combobox

(OP)
loaded from a .csv file.
File is about 195000 lines long and one column
from the file is used to fill combo box

RE: Remove non-consecutive duplicates from combobox

Couple of things that you might want to consder.  First, move the .csv file into a table from which you can remove the duplicates, or you might consider establishing an ADO connection to the .csv files and doing a SELECT DISTINCT.

RE: Remove non-consecutive duplicates from combobox

(OP)
I only have excel and it will not open the whole file, only a third of the file can be opened. I can not remove the duplicates from the file as they relate to other data and will be used later in other calculations. I am currently using AutoCAD VBA for this purpose, therefore can not use an ADO connection.
What is a SELECT DISTINCT? and how does it work? Form what I read it is not going to help me in doing the.

RE: Remove non-consecutive duplicates from combobox

Can you post the actual code that you use to populate the combobox?

RE: Remove non-consecutive duplicates from combobox

(OP)
The code opens the text file and then fills an array. At each point it places an item into the combobox

CODE

Private Sub cmdInput_Click()
On Error Resume Next
Dim blnError As Boolean
blnError = True
blnArrayFilled = False
varFileNum = FreeFile 'set as freefile so that program can set any file open as num
start_time = Timer
'Set a filter for opening files to open specific files only
dlgMain.Filter = "Text Files(*.CSV)|*.csv|"
'Data Files(*.DTA)|*.dta|Text Files (*.TXT)|*.txt"
dlgMain.ShowOpen             'show file open dialog box
If dlgMain.filename <> "" Then
    Open dlgMain.filename For Input As varFileNum
 If blnError <> False Then
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(dlgMain.filename)
    Set a = f.OpenAsTextStream(1)
    'count the number of lines in the text file
    Do While a.AtEndOfStream <> True
    ''place a line into a variable
        retstring = a.ReadLine
    ''count that line
        intI = intI + 1
    Loop
   ''count the number of commas
        ''PROBLEM: Skips consecutive commas therefore is two down on number of columns
    Call CountColumns
    'reset the text stream
    Set a = f.OpenAsTextStream(1)
    'redefine the array
    ReDim TempArray(intI - 1, intColumnCount + 2)
    ''loop through the text file one line at a time and place into the array
       I = 0
        Do While a.AtEndOfStream <> True
            retstring = a.ReadLine
            varText = Split(retstring, ",")
            For J = 0 To intColumnCount + 2
                varText = Split(retstring, ",")
                TempArray(I, J) = varText(J)
            Next J
           ''fills the combo box here
            cmbPropType.AddItem TempArray(I, 9)
            I = I + 1
        Loop
   MsgBox ("Sucess")
Else
    Close #varFileNum
    Exit Sub
    End If
End If
dlgMain.filename = ""
blnArrayFilled = True
Close #varFileNum
 
    stop_time = Timer

    lblInput.Caption = Format$(stop_time - start_time, _
        "0.00") & " sec"
  End Sub

RE: Remove non-consecutive duplicates from combobox

Inside the following loop, at the indicated location, you can check to see if the item has not already been loaded into the combobox.

CODE

Do While a.AtEndOfStream <> True
   retstring = a.ReadLine
   varText = Split(retstring, ",")
   For J = 0 To intColumnCount + 2
      varText = Split(retstring, ",")
      TempArray(I, J) = varText(J)
   Next J
   ''fills the combo box here

   IsLoaded = False
   For J = 0 To cmbPropType.ListCount - 1
      If (cmbPropType.Column(0, J) = TempArray(I, 9)) Then
         IsLoaded = True
         Exit For
      End If
      If (IsLoaded = False) Then      
         cmbPropType.AddItem TempArray(I, 9)
      Endif

   I = I + 1
Loop

RE: Remove non-consecutive duplicates from combobox

(OP)
thanks for the post CajunCenturion. This works perfect. Just one addition though:

CODE

Do While a.AtEndOfStream <> True
   retstring = a.ReadLine
   varText = Split(retstring, ",")
   For J = 0 To intColumnCount + 2
      varText = Split(retstring, ",")
      TempArray(I, J) = varText(J)
   Next J
   ''fills the combo box here

   IsLoaded = False
   For J = 0 To cmbPropType.ListCount - 1
      If (cmbPropType.Column(0, J) = TempArray(I, 9)) Then
         IsLoaded = True
         Exit For
      End If
   Next     ''Have to put a next here or it never gets into the loop
      If (IsLoaded = False) Then      
         cmbPropType.AddItem TempArray(I, 9)
      Endif

   I = I + 1
Loop

RE: Remove non-consecutive duplicates from combobox

Good catch, that Next is rather important.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close