PRB: ChDir or ChDrive Won't Change File / Directory List Boxes

Last reviewed: June 21, 1995
Article ID: Q86279
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 3.0
- Microsoft Visual Basic programming system for Windows, version 1.0

SYMPTOMS

Using the ChDir or ChDrive statement to change the current directory or drive does not change the listing of a file list box or a directory list box. However, the list changes if you run the program a second time in the VB.EXE environment.

RESOLUTION

To change the contents of a file list box or directory list box, set its Path property instead of using the ChDir or ChDrive statement.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior:

  1. Run Visual Basic, or from the File menu, choose New Project (ALT, F, N) if Visual Basic is already running. Form1 is created by default.

  2. Place a label (Label1), a file list box (File1), and a directory list box (Dir1) on to Form1.

  3. In the Form_Load event procedure, add the following code:

       Sub Form_Load ()
          ChDir "C:\DOS"
          Label1.Caption = CurDir$
       End Sub
    
    

  4. Press the F5 key to run the program. The label will display "C:\DOS", but the files listed are still those from the directory where Visual Basic was started.

  5. From the Run menu, choose End. Press the F5 key to run the program again. This time, the files listed are from the C:\DOS subdirectory.


Additional reference words: 1.00 2.00 3.00
KBCategory: kbprg kbcode kbprb
KBSubcategory: PrgCtrlsStd


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.