Results 1 to 5 of 5

Thread: ListBox & Multiple Selections

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    Canada
    Posts
    34

    Post

    Hello Everyone,

    I need to be able to select & run 1 or more "EXE" files from a list inside my ListBox:

    1- Pro. A
    2- Pro. B
    3- Pro. C

    Right now, when I select "A" and "C", for example, it starts "C" only. Please let me know how I can fix this.

    Regards.

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    Code:
        Dim i As Integer
        
        For i = 0 To List1.ListCount - 1
            If List1.Selected(i) = True Then
                Shell List1.List(i)
            End If
        Next i

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    Canada
    Posts
    34

    Post

    Thank You for your time & reply.

    It works now and as new VB user I am happy. But please read the following code and see if there is a better way:

    Private Sub Button2_Click()
    Dim i As Integer

    List1.List(0) = "notepad.exe"
    List1.List(1) = "calc.exe"
    List1.List(2) = "mspaint.exe"
    List1.List(3) = "C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe"
    List1.List(4) = "C:\Program Files\Microsoft Money\System\MSMONEY.EXE"
    List1.List(5) = "C:\Program Files\Copernic 2000 Plus\Copernic.exe"
    List1.List(6) = "C:\Lotus\Notes\notes.exe"
    List1.List(7) = "C:\Program Files\WinZip\WINZIP32.EXE"
    List1.List(8) = "C:\Program Files\QuickTime\QuickTimePlayer.exe"
    List1.List(9) = "C:\Program Files\Aventail\Connect\as32.exe"
    List1.List(10) = "C:\Program Files\CRT\CRT.EXE"
    List1.List(11) = "C:\Program Files\Rhino Software\FTP Voyager\FTPVoyager.exe"
    List1.List(12) = "C:\Program Files\ActiveSkin\SkinBuilder.exe"

    For i = 0 To List1.ListCount - 1

    If List1.Selected(i) = True Then

    Shell List1.List(i)

    End If

    Next i

    .
    .
    .

    Now, on my VB app menu, it is supposed to show a "list" of available applications that can be installed and not the "path". As a result, obviousley after selecting and running any of them, the "ListBox" changes the "name" of the apps with their "paths"!

    FYI, please note that each one of these apps should wait until the last one is installed and ended. Of course, I have already found a way of doing this part. :-)

    Regards.

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Store the Application Paths in an Array and use the ListIndex Property of the Listbox to Reference the List and Extract the Correct EXE Name/Path, this way the Actual List Item can contain any Text you wish. I would also use an external file to build the list of files, this way you can add/delete files without having to rebuild your application, ie.

    In a Flat File, "Apps.lst"..
    Notepad
    notepad.exe
    Calculator
    calc.exe
    MS Paint
    mspaint.exe
    Adobe Acrobat 4
    C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe
    MS Money
    C:\Program Files\Microsoft Money\System\MSMONEY.EXE
    Copernic 2000
    C:\Program Files\Copernic 2000 Plus\Copernic.exe
    Lotus Notes
    C:\Lotus\Notes\notes.exe
    WinZip
    C:\Program Files\WinZip\WINZIP32.EXE
    Quick Time
    C:\Program Files\QuickTime\QuickTimePlayer.exe
    Aventail
    C:\Program Files\Aventail\Connect\as32.exe
    CRT
    C:\Program Files\CRT\CRT.EXE
    FTP Voyager
    C:\Program Files\Rhino Software\FTP Voyager\FTPVoyager.exe
    Skin Builder
    C:\Program Files\ActiveSkin\SkinBuilder.exe
    Application Code
    Code:
    Dim aApps() As String
    
    Private Sub Form_Load()
        Dim iFile As Integer
        Dim iApp As Integer
        Dim sData As String
        Dim vSplit As Variant
        
        iFile = FreeFile
        Open "C:\Files\Apps.lst" For Input As iFile
            sData = Input(LOF(iFile), iFile)
        Close iFile
        vSplit = Split(sData, vbCrLf)
        ReDim Preserve aApps(UBound(vSplit) / 2)
        For iApp = 0 To UBound(vSplit) Step 2
            List1.AddItem vSplit(iApp)
            aApps(iApp / 2) = vSplit(iApp + 1)
        Next
    End Sub
    
    Private Sub List1_DblClick()
        Shell aApps(List1.ListIndex), vbNormalFocus
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    Canada
    Posts
    34

    Post

    Thank you very much Aaron. I really appreciate your help.

    Regards.

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