Sorting Array 
Author Message
 Sorting Array

I have this little program to load the files from a directory into an array
and open them 10 at a time for editing. (got great help from mvp's to get
this far ;-)

But I would like to sort the array before opening the files so they come to
me alphabetically making it easier to deal with them after the editing
process.

I keep getting an 'out of subscript' error in the sort routine and suspect
that it has something to do with the ubound statement of the array, but
after trying several flavors of fix-up applied to the coding for the sort, I
am still getting the error and am stumped. Could you please tell me where to
put the statement in the sorting code?  All help is much appreciated.

Here is the coding for the macro:

Sub GetFiles

Dim Resumes As String, FileArray() As String, Num As Long, OpnFile As Long
Dim PassNum As Integer, temp As String
Dim Upper As Long
ReDim FileArray(1200)
Num = 0
OpnFile = 0

''''''''''''' Load Array '''''''''''''''
Resumes = Dir$("C:\temp\*.txt")
Do While Len(Resumes) > 0
    FileArray(Num) = Resumes
    Num = Num + 1
    Resumes = Dir$
Loop
ReDim Preserve FileArray(Num - 1)
Upper = UBound(FileArray)

'''''''''''' Sort array '''''''''''''''''
For PassNum = 0 To Num
    For OpnFile = 1 To Num - PassNum

-- the following line is the one 'debug' points to as the problem --
    If FileArray(OpnFile) < FileArray(OpnFile + 1) Then

    Let temp = FileArray(OpnFile)
    Let FileArray(OpnFile) = FileArray(OpnFile + 1)
    Let FileArray(OpnFile + 1) = temp
    End If
    Next OpnFile
Next PassNum

''''''''''' Open files for editing '''''''''''''''
For OpnFile = 0 To 9
    If OpnFile <= Upper Then
        Documents.Open FileName:="C:\temp\" _
            & FileArray(OpnFile)
            Debug.Print OpnFile
    End If
Next



Sun, 05 Jan 2003 03:00:00 GMT  
 Sorting Array

Hi Jebus,

You can use the following to sort the array:

WordBasic.SortArray FileArray

--
Hope this helps.
Regards
ibby

Please post replies or follow-ups to the **newsgroup** so that participants
may benefit or contribute.


Quote:
> I have this little program to load the files from a directory into an
array
> and open them 10 at a time for editing. (got great help from mvp's to get
> this far ;-)

> But I would like to sort the array before opening the files so they come
to
> me alphabetically making it easier to deal with them after the editing
> process.

> I keep getting an 'out of subscript' error in the sort routine and suspect
> that it has something to do with the ubound statement of the array, but
> after trying several flavors of fix-up applied to the coding for the sort,
I
> am still getting the error and am stumped. Could you please tell me where
to
> put the statement in the sorting code?  All help is much appreciated.

> Here is the coding for the macro:

> Sub GetFiles

> Dim Resumes As String, FileArray() As String, Num As Long, OpnFile As Long
> Dim PassNum As Integer, temp As String
> Dim Upper As Long
> ReDim FileArray(1200)
> Num = 0
> OpnFile = 0

> ''''''''''''' Load Array '''''''''''''''
> Resumes = Dir$("C:\temp\*.txt")
> Do While Len(Resumes) > 0
>     FileArray(Num) = Resumes
>     Num = Num + 1
>     Resumes = Dir$
> Loop
> ReDim Preserve FileArray(Num - 1)
> Upper = UBound(FileArray)

> '''''''''''' Sort array '''''''''''''''''
> For PassNum = 0 To Num
>     For OpnFile = 1 To Num - PassNum

> -- the following line is the one 'debug' points to as the problem --
>     If FileArray(OpnFile) < FileArray(OpnFile + 1) Then

>     Let temp = FileArray(OpnFile)
>     Let FileArray(OpnFile) = FileArray(OpnFile + 1)
>     Let FileArray(OpnFile + 1) = temp
>     End If
>     Next OpnFile
> Next PassNum

> ''''''''''' Open files for editing '''''''''''''''
> For OpnFile = 0 To 9
>     If OpnFile <= Upper Then
>         Documents.Open FileName:="C:\temp\" _
>             & FileArray(OpnFile)
>             Debug.Print OpnFile
>     End If
> Next



Mon, 06 Jan 2003 03:00:00 GMT  
 Sorting Array

ibby
Works like a charm - I sure was trying to do it the hard way.
I looked in the VBA help file under arrays and sort and didn't find any
answers. Where should I have looked to find this simple solution? The help
files often leave me without the answers to help myself as much as I would
like.
Thanks again
Joanne

Quote:
> I have this little program to load the files from a directory into an
array
> and open them 10 at a time for editing. (got great help from mvp's to get
> this far ;-)

> But I would like to sort the array before opening the files so they come
to
> me alphabetically making it easier to deal with them after the editing
> process.

> I keep getting an 'out of subscript' error in the sort routine and suspect
> that it has something to do with the ubound statement of the array, but
> after trying several flavors of fix-up applied to the coding for the sort,
I
> am still getting the error and am stumped. Could you please tell me where
to
> put the statement in the sorting code?  All help is much appreciated.

> Here is the coding for the macro:

> Sub GetFiles

> Dim Resumes As String, FileArray() As String, Num As Long, OpnFile As Long
> Dim PassNum As Integer, temp As String
> Dim Upper As Long
> ReDim FileArray(1200)
> Num = 0
> OpnFile = 0

> ''''''''''''' Load Array '''''''''''''''
> Resumes = Dir$("C:\temp\*.txt")
> Do While Len(Resumes) > 0
>     FileArray(Num) = Resumes
>     Num = Num + 1
>     Resumes = Dir$
> Loop
> ReDim Preserve FileArray(Num - 1)
> Upper = UBound(FileArray)

> '''''''''''' Sort array '''''''''''''''''
> For PassNum = 0 To Num
>     For OpnFile = 1 To Num - PassNum

> -- the following line is the one 'debug' points to as the problem --
>     If FileArray(OpnFile) < FileArray(OpnFile + 1) Then

>     Let temp = FileArray(OpnFile)
>     Let FileArray(OpnFile) = FileArray(OpnFile + 1)
>     Let FileArray(OpnFile + 1) = temp
>     End If
>     Next OpnFile
> Next PassNum

> ''''''''''' Open files for editing '''''''''''''''
> For OpnFile = 0 To 9
>     If OpnFile <= Upper Then
>         Documents.Open FileName:="C:\temp\" _
>             & FileArray(OpnFile)
>             Debug.Print OpnFile
>     End If
> Next



Mon, 06 Jan 2003 03:00:00 GMT  
 Sorting Array
Hi Joanne & ibby,

For some time, I have been badgering MS to make the WordBasic help file from
Word 95 freely distributable. In addition to giving access to odd corners of
the Word object model that aren't otherwise documented, it provides a far
better description of the purposes and capabilities of Word's built-in
dialogs than has ever appeared in the Word 97 or Word 2000 documentation.

No luck yet....

Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email

Quote:

>Hi again Joanne,

>> Works like a charm - I sure was trying to do it the hard way.
>> I looked in the vba help file under arrays and sort and didn't find any
>> answers. Where should I have looked to find this simple solution? The
help
>> files often leave me without the answers to help myself as much as I
would
>> like.

>This is one of the WordBasic commands - the programming language used in
>versions prior to Word97. It is not well documented in the Word97/2000 Help
>files. There is no direct equivalent in VBA - the language used in
>Word97/2000, but it continues to be supported in these versions. I found
out
>about it in these newsgroups :-)

>--
>Hope this helps.
>Regards
>ibby

>Please post replies or follow-ups to the **newsgroup** so that participants
>may benefit or contribute.



Mon, 06 Jan 2003 03:00:00 GMT  
 Sorting Array
Please keep badgering - I often read on these newsgroups of people not being
able to find what they need in the help files - how frustrating.
I sure am glad (and I know I am not alone) that you MVPs are out there to
fill in the gaps Microsoft has left us with. Keep up the good work, Ibby and
Jonathan and all of you.
Joanne

Quote:
> Hi Joanne & ibby,

> For some time, I have been badgering MS to make the WordBasic help file
from
> Word 95 freely distributable. In addition to giving access to odd corners
of
> the Word object model that aren't otherwise documented, it provides a far
> better description of the purposes and capabilities of Word's built-in
> dialogs than has ever appeared in the Word 97 or Word 2000 documentation.

> No luck yet....

> Regards
> Jonathan West - Word MVP
> MultiLinker - Automated generation of hyperlinks in Word
> Conversion to PDF & HTML
> http://www.multilinker.com
> Word FAQs at http://www.multilinker.com/wordfaq
> Please post any follow-up in the newsgroup. I do not reply to Word
questions
> by email


> >Hi again Joanne,

> >> Works like a charm - I sure was trying to do it the hard way.
> >> I looked in the vba help file under arrays and sort and didn't find any
> >> answers. Where should I have looked to find this simple solution? The
> help
> >> files often leave me without the answers to help myself as much as I
> would
> >> like.

> >This is one of the WordBasic commands - the programming language used in
> >versions prior to Word97. It is not well documented in the Word97/2000
Help
> >files. There is no direct equivalent in VBA - the language used in
> >Word97/2000, but it continues to be supported in these versions. I found
> out
> >about it in these newsgroups :-)

> >--
> >Hope this helps.
> >Regards
> >ibby

> >Please post replies or follow-ups to the **newsgroup** so that
participants
> >may benefit or contribute.



Mon, 06 Jan 2003 03:00:00 GMT  
 Sorting Array
Hi again Joanne,

Quote:
> Works like a charm - I sure was trying to do it the hard way.
> I looked in the vba help file under arrays and sort and didn't find any
> answers. Where should I have looked to find this simple solution? The help
> files often leave me without the answers to help myself as much as I would
> like.

This is one of the WordBasic commands - the programming language used in
versions prior to Word97. It is not well documented in the Word97/2000 Help
files. There is no direct equivalent in VBA - the language used in
Word97/2000, but it continues to be supported in these versions. I found out
about it in these newsgroups :-)

--
Hope this helps.
Regards
ibby

Please post replies or follow-ups to the **newsgroup** so that participants
may benefit or contribute.



Tue, 07 Jan 2003 03:00:00 GMT  
 Sorting Array

Here comes Howard's speech number 23.

Buy the Word Developer's Kit by MSFT Press, even tho it applies to Word 6
and 7. I state my reasons along with the list of Word VBA books at
http://www.standards.com/users/kaikow/

Also the Office 2000 VB Programmer's Guide may be quite useful.

--
Please post your response to the newsgroup.

Quote:
> ibby
> Works like a charm - I sure was trying to do it the hard way.
> I looked in the vba help file under arrays and sort and didn't find any
> answers. Where should I have looked to find this simple solution? The help
> files often leave me without the answers to help myself as much as I would
> like.
> Thanks again
> Joanne


> > I have this little program to load the files from a directory into an
> array
> > and open them 10 at a time for editing. (got great help from mvp's to
get
> > this far ;-)

> > But I would like to sort the array before opening the files so they come
> to
> > me alphabetically making it easier to deal with them after the editing
> > process.

> > I keep getting an 'out of subscript' error in the sort routine and
suspect
> > that it has something to do with the ubound statement of the array, but
> > after trying several flavors of fix-up applied to the coding for the
sort,
> I
> > am still getting the error and am stumped. Could you please tell me
where
> to
> > put the statement in the sorting code?  All help is much appreciated.

> > Here is the coding for the macro:

> > Sub GetFiles

> > Dim Resumes As String, FileArray() As String, Num As Long, OpnFile As
Long
> > Dim PassNum As Integer, temp As String
> > Dim Upper As Long
> > ReDim FileArray(1200)
> > Num = 0
> > OpnFile = 0

> > ''''''''''''' Load Array '''''''''''''''
> > Resumes = Dir$("C:\temp\*.txt")
> > Do While Len(Resumes) > 0
> >     FileArray(Num) = Resumes
> >     Num = Num + 1
> >     Resumes = Dir$
> > Loop
> > ReDim Preserve FileArray(Num - 1)
> > Upper = UBound(FileArray)

> > '''''''''''' Sort array '''''''''''''''''
> > For PassNum = 0 To Num
> >     For OpnFile = 1 To Num - PassNum

> > -- the following line is the one 'debug' points to as the problem --
> >     If FileArray(OpnFile) < FileArray(OpnFile + 1) Then

> >     Let temp = FileArray(OpnFile)
> >     Let FileArray(OpnFile) = FileArray(OpnFile + 1)
> >     Let FileArray(OpnFile + 1) = temp
> >     End If
> >     Next OpnFile
> > Next PassNum

> > ''''''''''' Open files for editing '''''''''''''''
> > For OpnFile = 0 To 9
> >     If OpnFile <= Upper Then
> >         Documents.Open FileName:="C:\temp\" _
> >             & FileArray(OpnFile)
> >             Debug.Print OpnFile
> >     End If
> > Next



Wed, 08 Jan 2003 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Sorting Arrays

2. Sort Array

3. Access 97: Sorting Arrays

4. sort array in vba

5. Sorting arrays - Excel97 VBA

6. Sorting arrays

7. Sorting arrays in VBA

8. Sort Array

9. Sorting Arrays

10. Sorting array of structures

11. Sorting arrays

12. Sorting arrays

 

 
Powered by phpBB® Forum Software