From: Karl E. Peterson on
Hi Folks --

I just wanted to be sure about something, so I wrote up a little test...

Option Explicit

Private Sub Command1_Click()
Debug.Print Dir("c:\*.*")
End Sub

Private Sub Command2_Click()
Debug.Print Dir("nul")
End Sub

Compiling that, and watching it in TaskMgr, I see the Handle count rise when I press
Command1 and drop when I press Command2. I've tried googling for this, to no avail,
but I know I've seen threads here before about releasing the search handle VB
creates by calling FindFirstFile on a Dir.

I did find posts suggesting that passing vbNullString would do it too, but that
doesn't seem to be the case given the above test. Anyone have any thoughts on this?

Thanks... Karl
--
..NET: It's About Trust!
http://vfred.mvps.org


From: Billl on
--->
> Hi Folks --
>
> I just wanted to be sure about something, so I wrote up a little test...
>
> Option Explicit
>
> Private Sub Command1_Click()
> Debug.Print Dir("c:\*.*")
> End Sub
>
> Private Sub Command2_Click()
> Debug.Print Dir("nul")
> End Sub
>
> Compiling that, and watching it in TaskMgr, I see the Handle count rise when I press
> Command1 and drop when I press Command2. I've tried googling for this, to no avail,
> but I know I've seen threads here before about releasing the search handle VB
> creates by calling FindFirstFile on a Dir.
>
> I did find posts suggesting that passing vbNullString would do it too, but that
> doesn't seem to be the case given the above test. Anyone have any thoughts on this?
>
> Thanks... Karl

Karl:

I don't think that your "nul" is actually vbNullString. Isn't it simply
a three-character string of "n", "u", and "l"?

Billl
From: Tony Proctor on
The "nul" is the Windows "null device" (i.e. a special file name) and
nothing to do with vbNullString Bill

Karl, you may be thinking of my original post on this subject:
http://groups.google.ie/group/microsoft.public.vb.general.discussion/msg/5e589d1e61920a5e?hl=en

Tony Proctor

"Billl" <whatever(a)whichever.com> wrote in message
news:Oj5ROLL3IHA.3508(a)TK2MSFTNGP02.phx.gbl...
> --->
>> Hi Folks --
>>
>> I just wanted to be sure about something, so I wrote up a little test...
>>
>> Option Explicit
>>
>> Private Sub Command1_Click()
>> Debug.Print Dir("c:\*.*")
>> End Sub
>>
>> Private Sub Command2_Click()
>> Debug.Print Dir("nul")
>> End Sub
>>
>> Compiling that, and watching it in TaskMgr, I see the Handle count rise
>> when I press Command1 and drop when I press Command2. I've tried
>> googling for this, to no avail, but I know I've seen threads here before
>> about releasing the search handle VB creates by calling FindFirstFile on
>> a Dir.
>>
>> I did find posts suggesting that passing vbNullString would do it too,
>> but that doesn't seem to be the case given the above test. Anyone have
>> any thoughts on this?
>>
>> Thanks... Karl
>
> Karl:
>
> I don't think that your "nul" is actually vbNullString. Isn't it simply a
> three-character string of "n", "u", and "l"?
>
> Billl


From: expvb on
Try one of the following to see which one works:

1 - Specify a path that can not possibly exist, such as a long file name
with random characters. Internally, FindFirstFile should not find a first
file.

2 - Specify a path that contains invalid characters.

3 - From the Remarks section of FindFirstFile, "An attempt to open a search
with a trailing backslash will always fail.", so using "C:\" will always
fail. Normally "C:\*" should be used in that case to search the root of the
C: drive.



From: PeterD on
On Wed, 2 Jul 2008 17:39:15 -0700, "Karl E. Peterson" <karl(a)mvps.org>
wrote:

>Hi Folks --
>
>I just wanted to be sure about something, so I wrote up a little test...
>
> Option Explicit
>
> Private Sub Command1_Click()
> Debug.Print Dir("c:\*.*")
> End Sub
>
> Private Sub Command2_Click()
> Debug.Print Dir("nul")
> End Sub
>
>Compiling that, and watching it in TaskMgr, I see the Handle count rise when I press
>Command1 and drop when I press Command2. I've tried googling for this, to no avail,
>but I know I've seen threads here before about releasing the search handle VB
>creates by calling FindFirstFile on a Dir.
>
>I did find posts suggesting that passing vbNullString would do it too, but that
>doesn't seem to be the case given the above test. Anyone have any thoughts on this?
>
>Thanks... Karl

In Dir("nul") you (probably) don't have a folder named "nul" so the
dir command completes, and frees its handle? I think you will find the
same is true when the Dir() is called (no parameter) sufficiently to
enumerate all the items in the given folder based on the first call
that creates the handle.