PC Review


Reply
Thread Tools Rate Thread

Need Help with ARRAYS

 
 
Jack
Guest
Posts: n/a
 
      17th Apr 2004
I am having some trouble understanding arrays and how to Sort them.
The following code bellow looks for txt files in a specific directory.
The problem is that the 'DIR' function grabs the filenames randomly
as explained in the HELP file as Follows;
"Tip Because file names are retrieved in no particular
order, you may want to store returned file names in an array,
and then sort the array."
First, How would I define and populate an array that would store
the .txt files from a specific Directory.
The number of txt files in the directory will vary.
Second, How would I Sort The Array So that the files are are in the same
order as the Application.FileSearch.FoundFiles.Count

The code bellow is just a snippet of code from the Help file that I modified
But as you can tell I'm beginning to lose the understanding of what is going
on.
Please, any help is most appreciated.

With Application.FileSearch
.LookIn = sFilePath(j)
.FileName = "*.txt"
If .Execute() > 0 Then
MyFile = Dir(sFilePath(j))
For I = 1 To .FoundFiles.Count
MyFile = Left(MyFile, Len(MyFile) - 4) 'Removes the .txt
Extension
Application.Loadfromtext Forms, MyFile, .FoundFiles(I)
MyFile = Dir 'Get the next file in the same directory if there
is more than one.
Next I
End With



 
Reply With Quote
 
 
 
 
Tim Ferguson
Guest
Posts: n/a
 
      17th Apr 2004
"Jack" <(E-Mail Removed)> wrote in
news:#(E-Mail Removed):

> First, How would I define and populate an array that would store
> the .txt files from a specific Directory.
>


To be honest, I would just use the Files collection of the Folder object of
the FileSystemObject in the (I think) VBScript library.

> Second, How would I Sort The Array So that the files are are in the same
> order as the Application.FileSearch.FoundFiles.Count


Dunno: what order is that?

If you did know the order, there are entire books written on sorting
algoriths. Most programming courses spend most of their first term covering
them.

B Wishes


Tim F

 
Reply With Quote
 
Jack
Guest
Posts: n/a
 
      18th Apr 2004
Thanks for the response anyway;
I'm not sure I know what I'm talking about, But I'm sure I don't understand
what you're talking about.

Again Thanks for the response anyway....


"Tim Ferguson" <(E-Mail Removed)> wrote in message
news:Xns94CED9C5B8A18garbleme4455656@207.46.248.16...
> "Jack" <(E-Mail Removed)> wrote in
> news:#(E-Mail Removed):
>
> > First, How would I define and populate an array that would store
> > the .txt files from a specific Directory.
> >

>
> To be honest, I would just use the Files collection of the Folder object

of
> the FileSystemObject in the (I think) VBScript library.
>
> > Second, How would I Sort The Array So that the files are are in the same
> > order as the Application.FileSearch.FoundFiles.Count

>
> Dunno: what order is that?
>
> If you did know the order, there are entire books written on sorting
> algoriths. Most programming courses spend most of their first term

covering
> them.
>
> B Wishes
>
>
> Tim F
>



 
Reply With Quote
 
jdb
Guest
Posts: n/a
 
      18th Apr 2004
Jack

Why don'y you load files names into a table, and then sort the table
the way you want. I used to create tables with names of engineering
drawings and then hyper link them so you to click to see them.

If you want some code by a non-professional just let me know.

jdbeer




On Sat, 17 Apr 2004 13:31:07 -0400, "Jack" <(E-Mail Removed)> wrote:

>I am having some trouble understanding arrays and how to Sort them.
>The following code bellow looks for txt files in a specific directory.
>The problem is that the 'DIR' function grabs the filenames randomly
>as explained in the HELP file as Follows;
> "Tip Because file names are retrieved in no particular
> order, you may want to store returned file names in an array,
> and then sort the array."
>First, How would I define and populate an array that would store
>the .txt files from a specific Directory.
>The number of txt files in the directory will vary.
>Second, How would I Sort The Array So that the files are are in the same
>order as the Application.FileSearch.FoundFiles.Count
>
>The code bellow is just a snippet of code from the Help file that I modified
>But as you can tell I'm beginning to lose the understanding of what is going
>on.
>Please, any help is most appreciated.
>
>With Application.FileSearch
> .LookIn = sFilePath(j)
> .FileName = "*.txt"
> If .Execute() > 0 Then
> MyFile = Dir(sFilePath(j))
> For I = 1 To .FoundFiles.Count
> MyFile = Left(MyFile, Len(MyFile) - 4) 'Removes the .txt
>Extension
> Application.Loadfromtext Forms, MyFile, .FoundFiles(I)
> MyFile = Dir 'Get the next file in the same directory if there
>is more than one.
> Next I
>End With
>
>
>


 
Reply With Quote
 
Tim Ferguson
Guest
Posts: n/a
 
      19th Apr 2004
"Jack" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> I'm not sure I know what I'm talking about, But I'm sure I don't
> understand what you're talking about.


The one usually goes with the other... <g>

Perhaps if you told us what you are trying to achieve, we may be able to
help more. There are lots of ways of manipulating files and folders, and
not all of them are suitable for all problems. I am a big fan of
"classical" programming techniques, but even I cannot remember the last
time I tried to populate and then sort an array!

B wishes


Tim F

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting native arrays to managed arrays Bob Altman Microsoft VC .NET 8 28th Feb 2008 12:33 AM
Trouble with arrays (transferring values between two arrays) Keith R Microsoft Excel Programming 4 14th Nov 2007 01:00 AM
Jagged Arrays Problem - How to Assign Arrays to an Array Zigs Microsoft Excel Programming 3 11th Apr 2007 02:39 AM
Working with ranges in arrays... or an introduction to arrays =?Utf-8?B?R2xlbg==?= Microsoft Excel Programming 5 10th Sep 2006 09:32 AM
Arrays - declaration, adding values to arrays and calculation Maxi Microsoft Excel Programming 1 17th Aug 2006 05:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:05 PM.