Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Populate Listbox from OpenFileDialog Multi-Select

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
alyssaweaver
865 Views, 2 Replies

Populate Listbox from OpenFileDialog Multi-Select

I really don't think this is too hard, but here it goes. I'll post my code below. I've enabled muti-select. After the user selects whatever files they want, it's supposed to populate the list box. Instead, it concatenates it all onto one line separated by "|" for each file. Any ideas of how to get them to separate?

 

Private Sub cmdSourceAdd_Click()
    Dim oFileDlg As FileDialog
    ' Create a new FileDialog object.
    Call ThisApplication.CreateFileDialog(oFileDlg)

    ' Define the filter to select part and assembly files or any file.
    oFileDlg.Filter = "Inventor Files (*.iam;*.ipt;*.idw;*.dwg)|*.iam;*.ipt;*.idw;*.dwg|All Files (*.*)|*.*"
    ' Define the part and assembly files filter to be the default filter.
    oFileDlg.FilterIndex = 1
    oFileDlg.MultiSelectEnabled = True

    ' Set the title for the dialog.
    oFileDlg.DialogTitle = "Open File Test"

    ' Set the initial directory that will be displayed in the dialog.
    'oFileDlg.InitialDirectory = ThisApplication.FileOptions.ProjectsPath

    ' Set the flag so an error will be raised if the user clicks the Cancel button.
    oFileDlg.CancelError = True

    ' Show the open dialog.  The same procedure is also used for the Save dialog.
    ' The commented code can be used for the Save dialog.
    On Error Resume Next
    oFileDlg.ShowOpen
'    oFileDlg.ShowSave

    ' If an error was raised, the user clicked cancel, otherwise display the filename.
    If Err Then
        MsgBox "User cancelled out of dialog"

    ElseIf Not oFileDlg.fileName = "" Then
        lstSource.AddItem oFileDlg.fileName
        'WHAT GOES HERE???
       
    End If

End Sub

 

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"
2 REPLIES 2
Message 2 of 3
alyssaweaver
in reply to: alyssaweaver

One thing I tried is below. This sets the program in to an endless loop because it doesn't know how to go to the next file.

 

Private Sub cmdSourceAdd_Click()
    Dim oFileDlg As FileDialog
    ' Create a new FileDialog object.
    Call ThisApplication.CreateFileDialog(oFileDlg)

    ' Define the filter to select part and assembly files or any file.
    oFileDlg.Filter = "Inventor Files (*.iam;*.ipt;*.idw;*.dwg)|*.iam;*.ipt;*.idw;*.dwg|All Files (*.*)|*.*"
    ' Define the part and assembly files filter to be the default filter.
    oFileDlg.FilterIndex = 1
    oFileDlg.MultiSelectEnabled = True

    ' Set the title for the dialog.
    oFileDlg.DialogTitle = "Open File Test"

    ' Set the initial directory that will be displayed in the dialog.
    'oFileDlg.InitialDirectory = ThisApplication.FileOptions.ProjectsPath

    ' Set the flag so an error will be raised if the user clicks the Cancel button.
    oFileDlg.CancelError = True

    ' Show the open dialog.  The same procedure is also used for the Save dialog.
    ' The commented code can be used for the Save dialog.
    On Error Resume Next
    oFileDlg.ShowOpen
'    oFileDlg.ShowSave

    ' If an error was raised, the user clicked cancel, otherwise display the filename.
    If Err Then
        MsgBox "User cancelled out of dialog"

    ElseIf Not oFileDlg.fileName = "" Then
        lstSource.AddItem oFileDlg.fileName
        'WHAT GOES HERE???
        Do Until oFileDlg.fileName = ""
        Loop
        
    End If

End Sub

 

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"
Message 3 of 3
alyssaweaver
in reply to: alyssaweaver

Shout out to rjay75 for the answer!

 

    ElseIf Not oFileDlg.fileName = "" Then
        Dim fNames As Variant
        fNames = Split(oFileDlg.fileName, "|")
        Dim curName As Variant
        For Each curName In fNames
            lstSource.AddItem curName
        Next curName
    End If

 

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report