Re: Help with a long running process?



Thank you very very much Branco. This does indeed look like what I
need to solve the problem.

On 19 Mar 2007 14:27:29 -0700, "Branco Medeiros"
<branco.medeiros@xxxxxxxxx> wrote:

<snip>

Before the loop enters its initial cicle, it will first have to grab
all the files from all sub folders off the base path you specified.
This is what I was having the trouble with. I had hoped there was
something I didn't know about that would allow me to do a DoEvents in
there. As I'm constantly finding situations where there are more
elegant and much simpler ways to accomplish some of the things I'm
writing code for.


You can't put a DoEvents into this, cause it all will happen in the
GetFiles() instruction. Also, there's not much sense to put this in a
loop unless you want to do something with each file.
Thats exactly what I was doing. I was parsing the filenames, for each
file, into smaller segments. Then adding all bits dealing with that
filename into a class to store the parsed info. I was then adding each
class to a List.

One possible way to execute what you want is just to assign the array
of file names directly to listOfFiles (which I assume is a List(Of
String)) or return it as an array.

Nevertheless, if you want to have some control over the loop, you may
consider loading the files folder by folder:

<aircode>
Sub LoadFiles(ByVal Folder As String, _
ByVal List As List(Of String))
Dim Items() As String = _
System.IO.Directory.GetFiles(Folder)
ShowProgress(Folder, Items)
Application.DoEvents() '<-- Ops...
List.AddRange(Items)
For Each SubFolder As String _
In System.IO.Directory.GetDirectories(Folder)
Try
LoadFiles(SubFolder, List)
Catch Ex As Exception
End Try
Next
End Sub
</aircode>

As you can see, it's a recursive method that calls itself for each sub
folder. The 'Ops...' remark near DoEvents is just to remind you that
there are better ways to keep the UI alive during a long operation
(threads or the background worker, for instance). Anyway, this may
become your starting point...
I had initially started with something fairly similar to this. Then I
found a supposedly simpler way to do this and changed it around. But
that was back when I was only dealing with about 5,000-10,000
filenames. I completely forgot about it. Thank you for pointing it out
to me. This should solve the problem.

Kyote wrote:
I'm trying to make, what I thought, would be a simple application.

Join the club... =)))
LMAO, I'm happy to see it's not just me. Speaking of which, how do
you, more effectively, deal with program idea/concept improvements?

I often think of a simple app I'd like to make to simplify something I
want to do. Then while I'm writing away at it I get the 'Brillant'
idea for an improvement, or added feature. Something that can
'supposedly' make the app so much better than my original idea would
have been. But after a couple of those I sometimes get pretty confused
and frustrated.

Is there some kind of best practice or something for managing new
idea's/features? I guess I can stubbornly stick to my original app
specifications. Then once it's finished maybe then go back and revise
them. But is there a better way?
---
Kyote
.



Relevant Pages

  • Re: Recognizing When An IE window changes URLs and closing the IE
    ... lpClassName As String, ByVal lpWindowName As String) As Long ... Private Sub x_NewWindow2 ... Dim ie1 As New IEClass ... On Error GoTo Here ' Error handling sequence that breaks the loop, ...
    (microsoft.public.excel.programming)
  • Re: Looping through file system
    ... Get the folder from user using the ... Set up a loop based on stopping the loop when the result from the Dir ... Dim strDirectory As String, strFilter As String ... Dim strFileName As String, strInputFileName As String ...
    (microsoft.public.access.modulesdaovba)
  • Re: Want to modify this VBA code snippet
    ... be in a lower folder. ... Sub Combinebooks() ... >> I want to combine the three workbooks in each Direcotry automatically>> in ... >> pszpath As String) As Long ...
    (microsoft.public.excel.programming)
  • Re: Form coding Help - Part 2
    ... > Dim stDocName As String ... > Exit Sub ... the above will store the file in the same folder as the ...
    (microsoft.public.access.formscoding)
  • Folder Search VB6 SP6
    ... In My Music Folder I have added 3 test Folders. ... Call ScanMusicFolder 'Call Sub ... Private Function TrimNull(ByRef inString As String) As String ... Public Function AppendTrailingSlash(ByRef inPath As String, ...
    (microsoft.public.vb.general.discussion)

Loading