+ Reply to Thread
Results 1 to 5 of 5

Sorting an array-multiple select seems uncontrollable

  1. #1
    Peter Rooney
    Guest

    Sorting an array-multiple select seems uncontrollable

    Good afternoon.

    I have a routine that allows the user to select one or several files from
    the fileopen dialog box. If the user selects multiple files, is there any way
    in which they can be stored to the elements of the array in alphabetical
    order e.g. element 1 contains test1.xls, element 2 contains test4.xls,
    element 3 contains testX.xls etc?

    At the moment, a multiple select seems uncontrollable as to which filename
    gets stored in each element.

    Thanks in advance and see you in the morning!

    Pete



  2. #2
    Martin
    Guest

    re: Sorting an array-multiple select seems uncontrollable

    Seeing as you're skiving off, here's a selection of sorting algorithms to
    make you work tomorrow:
    http://www.cs.ubc.ca/spider/harrison...ting-demo.html

    "Peter Rooney" wrote:

    > Good afternoon.
    >
    > I have a routine that allows the user to select one or several files from
    > the fileopen dialog box. If the user selects multiple files, is there any way
    > in which they can be stored to the elements of the array in alphabetical
    > order e.g. element 1 contains test1.xls, element 2 contains test4.xls,
    > element 3 contains testX.xls etc?
    >
    > At the moment, a multiple select seems uncontrollable as to which filename
    > gets stored in each element.
    >
    > Thanks in advance and see you in the morning!
    >
    > Pete
    >
    >


  3. #3
    Tom Ogilvy
    Guest

    re: Sorting an array-multiple select seems uncontrollable

    This uses the slow but simple bubble sort, but it shouldn't be an issue with
    a small number of files.

    Sub SortFiles()
    Dim i As Long, temp As String
    Dim v As Variant, j As Long
    v = Application.GetOpenFilename(MultiSelect:=True)
    If UBound(v) - LBound(v) > 0 Then
    For i = LBound(v) To UBound(v) - 1
    For j = i + 1 To UBound(v)
    If LCase(v(i)) > LCase(v(j)) Then
    temp = v(i)
    v(i) = v(j)
    v(j) = temp
    End If
    Next
    Next
    End If
    j = 1
    For i = LBound(v) To UBound(v)
    Cells(j, 3).Value = v(i)
    j = j + 1
    Next
    End Sub

    --
    Regards,
    Tom Ogilvy


    "Peter Rooney" <[email protected]> wrote in message
    news:[email protected]...
    > Good afternoon.
    >
    > I have a routine that allows the user to select one or several files from
    > the fileopen dialog box. If the user selects multiple files, is there any

    way
    > in which they can be stored to the elements of the array in alphabetical
    > order e.g. element 1 contains test1.xls, element 2 contains test4.xls,
    > element 3 contains testX.xls etc?
    >
    > At the moment, a multiple select seems uncontrollable as to which filename
    > gets stored in each element.
    >
    > Thanks in advance and see you in the morning!
    >
    > Pete
    >
    >




  4. #4
    Peter Rooney
    Guest

    re: Sorting an array-multiple select seems uncontrollable

    Martin,

    I was NOT skiving off!
    I prefer to think of it as ensuring that I don't succumb to executive
    burnout via overwork, thus inconveniencing my employer... :-)

    I'll take a look - thanks!

    Pete

    "Martin" wrote:

    > Seeing as you're skiving off, here's a selection of sorting algorithms to
    > make you work tomorrow:
    > http://www.cs.ubc.ca/spider/harrison...ting-demo.html
    >
    > "Peter Rooney" wrote:
    >
    > > Good afternoon.
    > >
    > > I have a routine that allows the user to select one or several files from
    > > the fileopen dialog box. If the user selects multiple files, is there any way
    > > in which they can be stored to the elements of the array in alphabetical
    > > order e.g. element 1 contains test1.xls, element 2 contains test4.xls,
    > > element 3 contains testX.xls etc?
    > >
    > > At the moment, a multiple select seems uncontrollable as to which filename
    > > gets stored in each element.
    > >
    > > Thanks in advance and see you in the morning!
    > >
    > > Pete
    > >
    > >


  5. #5
    Peter Rooney
    Guest

    re: Sorting an array-multiple select seems uncontrollable

    Tom,

    Thanks very much for this - it works fine! :-)

    Regards

    Pete




    "Tom Ogilvy" wrote:

    > This uses the slow but simple bubble sort, but it shouldn't be an issue with
    > a small number of files.
    >
    > Sub SortFiles()
    > Dim i As Long, temp As String
    > Dim v As Variant, j As Long
    > v = Application.GetOpenFilename(MultiSelect:=True)
    > If UBound(v) - LBound(v) > 0 Then
    > For i = LBound(v) To UBound(v) - 1
    > For j = i + 1 To UBound(v)
    > If LCase(v(i)) > LCase(v(j)) Then
    > temp = v(i)
    > v(i) = v(j)
    > v(j) = temp
    > End If
    > Next
    > Next
    > End If
    > j = 1
    > For i = LBound(v) To UBound(v)
    > Cells(j, 3).Value = v(i)
    > j = j + 1
    > Next
    > End Sub
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Peter Rooney" <[email protected]> wrote in message
    > news:[email protected]...
    > > Good afternoon.
    > >
    > > I have a routine that allows the user to select one or several files from
    > > the fileopen dialog box. If the user selects multiple files, is there any

    > way
    > > in which they can be stored to the elements of the array in alphabetical
    > > order e.g. element 1 contains test1.xls, element 2 contains test4.xls,
    > > element 3 contains testX.xls etc?
    > >
    > > At the moment, a multiple select seems uncontrollable as to which filename
    > > gets stored in each element.
    > >
    > > Thanks in advance and see you in the morning!
    > >
    > > Pete
    > >
    > >

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1