Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Exclude a file from Listbox

  1. #1
    100 Club
    Join Date
    2007-07
    Posts
    104
    Login to Give a bone
    0

    Default Exclude a file from Listbox

    Hi

    I have made a userform with a listbox that shows all the .dwg files in a folder that is chosen by the user. The .dwg files can then be processed by clicking an ok button.

    This is useful for running scripts on multiple files, filling in standard values for certain blocks in a project, etc. I now want to exclude one of the files in the selected folder (filename 20001001.dwg) so it can be used for making a drawing list. The file will be used in a module that opens the drawings one by one, gets attribute values, and copies those values to certain coordinates 20001001 (as a list).

    The problem is, I can 't seem to find a way of excluding this 20001001.dwg file from the listbox so it won 't be processed. I have searched all over the web and tried various things, but I guess am not experienced enough to know where the golden vain is. Can anyone please point me in the right direction?

  2. #2
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Exclude a file from Listbox

    Hope this will get you started

    ~'J'~
    Attached Files Attached Files

  3. #3
    100 Club
    Join Date
    2007-07
    Posts
    104
    Login to Give a bone
    0

    Default Re: Exclude a file from Listbox

    Thanks for the quick and thorough reply.
    This is something I can work with, thanks a lot!

  4. #4
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Exclude a file from Listbox

    Glad if this will helps
    Happy computing

    ~'J'~

  5. #5
    100 Club
    Join Date
    2007-07
    Posts
    104
    Login to Give a bone
    0

    Default Re: Exclude a file from Listbox

    It does give me some more of an idea of how to approach the files in the Listbox, but I am still not all the way there. This is what I would really like the program to do in the end:

    1) the program automatically (without a "remove" button) recognises the filename "20001001.dwg", and removes it from the listbox before the listbox is shown.

    2) This 20001001.dwg "stringfilename" is then stored in the memory so it will be used to save info on the rest of te files (make a drawinglist).

    The part of my form that collects the file info looks like this:

    Code:
    Private Sub CommandGetList_Click()
    
        Dim FolderName As String
        Dim frm As New ProjectDrawings
        
        MsgBox ("Select the map of the project")
    
        FolderName = ShowDialog2()
        
        If FolderName <> vbNullString Then
            Dim colDirList As New Collection
            Dim varItem As Variant
        
            ' "dwg" for autocad files...
            Call FindFiles1(colDirList, FolderName, "dwg", True)
            
            ' Add files to the form.
            For Each varItem In colDirList
                frm.ListBoxTwo.AddItem (varItem)
            Next
            
            ' Select all files in the form
            If frm.ListBoxTwo.ListCount > 0 Then
                For i = 0 To frm.ListBoxTwo.ListCount - 1
                    frm.ListBoxTwo.Selected(i) = True
                Next
            End If
    
            ' Show form in wich some files can be left unselected so they aren 't processed
            frm.Show
    
        End If
    
    End Sub
    Perhaps (as you have been of good help so far) you can help me find a way of making that selection process work automatically?
    Last edited by darfnuggi; 2008-04-08 at 04:44 PM.

  6. #6
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Exclude a file from Listbox

    Perhaps you can exclude the particular
    item from process, something like:
    Code:
            ' Add files to the form.
            For Each varItem In colDirList
                 if varitem<>"20001001.dwg" then
                frm.ListBoxTwo.AddItem (varItem)
                end if
            Next
    ~'J'~

  7. #7
    100 Club
    Join Date
    2007-07
    Posts
    104
    Login to Give a bone
    0

    Default Re: Exclude a file from Listbox

    Thank you again for helping me. I tried what you mentioned above, but it didn 't work as well as something else I tried before. I can make the program recognise the file within the "findfile" sub referred to in the sub above. In the findfile sub I type the following:

    Code:
        If Findfile <> CurDir$ & "\" & "20001001.dwg" Then
        MsgBox "20001001 gevonden" ' Call function?
        End If
    I have been trying to put something in the msgbox line that will remove the file, (or assign a value to it so I can call it later):

    THEN frm.ListBoxTwo.RemoveItem ("20001001.dwg")

    THEN ListBoxTwo.DeleteSelected

    I see you seem to use AddItem to remove an item. You also used RemoveItem on two accasions in the ListMan project:

    Code:
     
    Private Sub cmdRemove_Click()
    lstFiles.RemoveItem (lstFiles.ListIndex)
    lstFiles.ListIndex = 0
    lstFiles.SetFocus
    End Sub
    I do not understand exactly how that works. As you can see by now, I am not very good at this, I am still learning. The things I tried above don 't work, and I take a long time looking for good approaches, so any ideas that will put me on the right track are greatly appreciated.

  8. #8
    Active Member
    Join Date
    2007-12
    Posts
    68
    Login to Give a bone
    0

    Default Re: Exclude a file from Listbox

    Personally, I would'nt add the filtering code to the findfiles routine. That seems to be generic, re-suable code, and adding a special filter at that point will cause problems later when you go to re-use the code down the road.

    Secondly, I wouldnt add, and then remove, an item from the listbox - you're looping thru the listbox twice. Interface elements like listboxes are slow enough without having to repeat what you're doing.

    FindFiles returns an array of names, in memory. Nice and fast. I would just ignore adding the item to the listbox if it matches the 'magic word' of "20001001.dwg"

    Thirdly, since you are using a 'magic word' (a hardcoded string) and want to reuse it more in the future, Id make "20001001.dwg" a string constant, at least shared at the module level. Then if you wanted to change this name , you change it in ONE place in your code - located handily at the top of the module.

    ' quick snippet: at the Module level:
    Const FilterFile as String = "20001001.dwg"

    ' and in your form code, to add to the listbox:
    For Each varItem In colDirList
    if varitem <> FilterFile then frm.ListBoxTwo.AddItem (varItem)
    Next varItem

  9. #9
    100 Club
    Join Date
    2007-07
    Posts
    104
    Login to Give a bone
    0

    Default Re: Exclude a file from Listbox

    Thank you for the step by step instructions and explanations.
    First, I will study the "Item" method "fixo" mentioned more thoroughly.
    The I'll slowly but surely work my way through the integration of these steps in my project.
    Thanks to both of you for putting me on the right track.

  10. #10
    100 Club
    Join Date
    2007-07
    Posts
    104
    Login to Give a bone
    0

    Default Re: Exclude a file from Listbox

    B_Roche, I now also see that the findfiles part of the program is not a good place to put in the filter. I think the best place to put is in the code I posted earlier. I've been playing around, trying to find a way to make this work with the ideas you and Fixo gave me. The result is this (mumbo jumbo, but it does something interesting)
    Code:
            Const filterfile As String = "20001001.dwg"
            
            If varitem <> filterfile Then
            frm.ListBoxOne.AddItem (filterfile)
            End If  ' Both Boxes contain 20001001 because both boxes are filled seperatly
            ' Else leaves only listboxone filled because case 1 rules out case 2
            ' I tried to work around that by select case.....end select, but didn 't find a way
     
            For Each varitem In colDirList
            frm.ListBoxTwo.AddItem (varitem)
            Next
            End If
            ' If varitem <> filterfile Then
            ' frm.ListBoxTwo.AddItem (ListBoxTwo.ListIndex)
            ' End If
    The way you put it B_Roche, sounds most logical, but if I do
    for each...if..then..else..next,
    I get the message;
    "next without for".
    It seems I am not allowed to put an
    if...then.. else..
    between a
    for each...next
    statement.
    [/code]
    So if anyone has any ideas that can add to the solution of this case, I would really like to know.
    Last edited by darfnuggi; 2008-06-27 at 11:49 AM.

Page 1 of 2 12 LastLast

Similar Threads

  1. DCL Listbox
    By LSElite in forum AutoLISP
    Replies: 4
    Last Post: 2013-04-30, 11:44 PM
  2. Rules - Add instead of exclude
    By Bryan Thatcher in forum NavisWorks - General
    Replies: 0
    Last Post: 2011-03-03, 02:03 PM
  3. exclude from void
    By Bryan Thatcher in forum Revit Architecture - General
    Replies: 2
    Last Post: 2010-08-13, 07:09 PM
  4. Listbox problems
    By Gary.stowell in forum VBA/COM Interop
    Replies: 2
    Last Post: 2009-09-15, 08:01 PM

Posting Permissions

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