Jump to content
Xtreme .Net Talk

Recommended Posts

Guest Tygur
Posted

Consider this VB6 code:

Dim TestDir As String
TestDir = "d:\testdir"
ChDrive Left(TestDir, 1)
ChDir TestDir
ChDrive "c:"
MsgBox CurDir(Left(TestDir, 1))

 

Assuming that the TestDir string is a full path to a directory that exists, that directory should be shown in the messagebox. If you test it out, it will perform as expected.

 

Now consider this VB.NET code:

        Dim TestDir As String
       TestDir = "d:\testdir"
       ChDrive(Left(TestDir, 1))
       ChDir(TestDir)
       ChDrive("c:")
       MsgBox(CurDir(Left(TestDir, 1)))

 

This code should do the same exact thing as the VB6 code I just showed you. In fact, it was the Visual Studio .NET IDE that converted the code for me.

 

If you run that VB.NET code, the directory shown in the message box doesn't seem to be the same as the one in TestDir if the directory in TestDir is on any drive other than drive C (or whichever drive that last ChDrive line changes to). Did I just find a bug, or did I miss something?

 

NOTE: the culprit is this line (taken from the VB.NET code):

ChDrive("c:")

 

Apparently, it's changing the current path on the drive it's changing from in the process of changing the current drive.

Guest Tygur
Posted

These "old methods" are still a part of the Visual Basic language. There is nothing in the help files that indicate that they should be avoided.

 

If I change this line:

ChDrive("c:")

 

..to this:

System.Environment.CurrentDirectory = "c:"

 

..or this:

System.IO.Directory.SetCurrentDirectory("c:")

 

...the results are still the same, by the way.

 

And yes, I know I could've left out the "System." part of both of those lines, but I left it in, anyway. (just in case anyone is thinking of commenting on that)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...