Microsoft KB Archive/184889

{|
 * width="100%"|

FIX: Dir Method of File-System Control Ignores vbNormal

 * }

Q184889

-

The information in this article applies to:


 * Microsoft Windows CE Toolkit for Visual Basic 5.0, version 1.0

-

SYMPTOMS
When using the vbNormal attribute in the Dir method of the File System control, no files are returned.

This problem occurs whether any specified files are Normal (GetAttr = 0) or Archive (GetAttr = 32).

Under Visual Basic 5.0, files flagged as Archive (GetAttr returns 32) are returned if the attribute parameter is set to vbNormal.

CAUSE
The Dir method does not interpret the vbNormal attribute as expected.

RESOLUTION
To work around this behavior, omit the attribute parameter from the Dir method and use the GetAttr method to check the attribute value (0 for vbNormal or 32 for vbArchive) when the items are read in.

STATUS
Microsoft has confirmed this to be a problem in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Windows CE Toolkit for Visual Basic 6.0.

Steps to Reproduce Behavior
 Start a new Windows CE project in Visual Basic 5.0. Click OK to dismiss the Project Properties dialog box. On the Project menu, click Components. Select "Microsoft CE File System Control 1.0" and click OK. Place a ListBox, a ComboBox and a File-System control on Form1.  Add the following code to the form:

     Private Sub Form_Load Combo1.AddItem "none" Combo1.AddItem "0 - vbNormal" Combo1.AddItem "2 - vbHidden" Combo1.AddItem "4 - vbSystem" Combo1.AddItem "8 - vbVolume" Combo1.AddItem "16 - vbDirectory" Combo1.ListIndex = 0 Combo1_Click End Sub

Private Sub Combo1_Click Dim curDir Dim curAttr Dim itemStr curDir = "\*.*" curAttr = "" itemStr = "" List1.Clear List1.AddItem "Attributes: " & Combo1.List(Combo1.ListIndex) Select Case Combo1.ListIndex Case 0 '"none" itemStr = FileSystem1.Dir(curDir) Case 1 '"0 - vbNormal" itemStr = FileSystem1.Dir(curDir, 0) Case 2 '"2 - vbHidden" itemStr = FileSystem1.Dir(curDir, 2) Case 3 '"4 - vbSystem" itemStr = FileSystem1.Dir(curDir, 4) Case 4 '"8 - vbVolume" itemStr = FileSystem1.Dir(curDir, 8) Case 5 '"16 - vbDirectory" itemStr = FileSystem1.Dir(curDir, 16) End Select While itemStr <> "" List1.AddItem itemStr & " - " & _ FileSystem1.GetAttr("\" & itemStr) itemStr = FileSystem1.Dir Wend End Sub  Run the project.</ol>

Notice that when "0 - vbNormal" is selected, no files are returned. This occurs whether the file has an attribute of Archive or Normal.

To work around the error in the sample code above, change the Case 1 code for the Select Case statement to read as follows:

<pre class="CODESAMP">Case 1 '"0 - vbNormal" itemStr = FileSystem1.Dir(curDir) While itemStr <> "" curAttr = FileSystem1.GetAttr("\" & itemStr) If curAttr = 0 Or curAttr = 32 Then List1.AddItem itemStr & " - " & curAttr End If     itemStr = FileSystem1.Dir Wend Exit Sub