Guest Tygur Posted July 25, 2002 Posted July 25, 2002 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. Quote
*Gurus* divil Posted July 25, 2002 *Gurus* Posted July 25, 2002 Why would you use those old methods of doing this? Personally I've never used a "current directory" in any version of Visual Basic. There is an Environment.CurrentDirectory, if that helps. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Guest Tygur Posted July 26, 2002 Posted July 26, 2002 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) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.