DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2005

    Why the file is saved in the different locations?

    I have the code as following to convert a DAT file to a TXT file,
    Sub DataImport(strPath As String, strTableName As String)
    'Variables used to create and modify the file extension
    Dim objFileSystem
    Dim objFile
    Dim strFileCopy As String
    Dim intExtPosition As Integer

    'Create an instance of the FileSystemObject to access
    'the local file system
    Set objFileSystem = CreateObject("Scripting.FileSystemObject")

    'Use the GetFile method to return a File object corresponding to the
    'file in a specified path.
    Set objFile = objFileSystem.GetFile(strPath)
    intExtPosition = InStr(objFile.Name, ".")
    If intExtPosition > 0 Then
    strFileCopy = Left(objFile.Name, intExtPosition - 1) & ".txt"
    strFileCopy = objFile.Name & ".txt"
    End If

    'Create a copy of the file with a .txt extension
    objFile.Copy strFileCopy, True
    'DoCmd.TransferText acImportDelim, , strTableName, strFileCopy, True
    End Sub
    The code is straightforward, but I don't understand why sometimes, when I run the code, the copy text file is saved in my current working directory (D:\VB6.0\Myfile.txt), and other times it is saved C:\MyDocument\Myfile.txt) ???
    Can you tell my why and how to "force" it to be saved only in one specific location?
    Thank you,

  2. #2
    Join Date
    Nov 2003
    Portland, OR
    If you want it saved in a specific folder, you must include the path in your strFileCopy variable.
    Phil Weber

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Aug 2005
    Kent, England
    If you start VB from the start menu or a desktop icon the program is launched from its installation folder and any files created within your code will be saved to that folder ("C:\Program Files\Microsoft Visual Studio\VB98" on my PC) unless you specify an explicit path.
    Similarly, if you start VB by double clicking a project file the default folder your code will use is the location of the project file.
    You can verify this by putting
    Debug.Print CurDir
    in your startup form.

Similar Threads

  1. Replies: 8
    Last Post: 03-08-2003, 06:25 PM
  2. How long before the next version??
    By _CAG in forum .NET
    Replies: 146
    Last Post: 08-12-2002, 10:40 PM
  3. Create Procedure
    By YC Choo in forum Database
    Replies: 5
    Last Post: 09-03-2001, 01:42 PM
  4. Finding file type
    By Ravi in forum VB Classic
    Replies: 0
    Last Post: 08-24-2001, 11:15 AM
  5. Replies: 3
    Last Post: 08-04-2000, 06:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.