Results 1 to 4 of 4

Thread: [RESOLVED] Drive and Directory Problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    80

    Resolved [RESOLVED] Drive and Directory Problem

    I have this error message when I try to use Drive and Directory
    "Run time error 76 Path not found "
    when I try to create a text file to root C or "C:\". It is ok if I create file in other directories rather than root C. What have caused it?

    My coding
    VB Code:
    1. Private Sub Command1_Click()
    2. 'all variables have been declared
    3.  
    4. InfoFile = Dir1.Path & "\" & Text1.Text
    5.          Open InfoFile For Output As #1
    6.         MsgBox "File " & InfoFile & " has been created to store students records", vbOKOnly + vbInformation, " File Creation"
    7.         Unload Me
    8.    
    9. End Sub
    10.  
    11. ' This event occurs when a new drive is selected
    12.  Sub Drive1_Change()
    13.     ' Trap an error if it occurs
    14.     On Error GoTo driveerr
    15.     ' change the folder path to the new drive
    16.     Dir1.Path = Drive1.Drive
    17.     ' change the file path
    18.     'File1.Path = Drive1.Drive
    19.     ' Save the new drive name
    20.     OldDrive = Drive1.Drive
    21.     'Exit procedure, no error has occured
    22.     Exit Sub
    23. driveerr:
    24.     ' error handling procedure
    25.     Select Case Err
    26.         Case 68
    27.             MsgBox "Drive not accessable"
    28.             ' Switch back to the previosu drive
    29.             Drive1.Drive = OldDrive
    30.             Exit Sub
    31.         Case Else
    32.             MsgBox "Unexpected Error." & Err & " : " & Error
    33.             Drive1.Drive = OldDrive
    34.             Exit Sub
    35.     End Select
    36. End Sub

    Thanks
    Last edited by RobDog888; Apr 17th, 2006 at 11:02 PM. Reason: Added [VBCODE] tags

  2. #2
    Frenzied Member litlewiki's Avatar
    Join Date
    Dec 2005
    Location
    Zeta Reticuli Distro:Ubuntu Fiesty
    Posts
    1,162

    Re: Drive and Directory Problem

    use a common dialog object it has more fetaures than the dir boxes
    cdlg
    __________________
    ________________0ооо___
    ___ооо0________(___)____
    __(___)_________) _/_____
    ___\_ (_________(_/______
    ____\_)_________________

  3. #3
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: Drive and Directory Problem

    The error occurs because the drive.drive returns "C:\", rather than "C:"
    use this
    VB Code:
    1. If Right(Dir1.Path, 1) = "\" Then
    2.     infofile = Dir1.Path & Text1.Text
    3. Else
    4.     infofile = Dir1.Path & "\" & Text1.Text
    5. End If
    to set the info file

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    80

    Re: Drive and Directory Problem

    Thanks, such simple thing sometimes doesn't come to mind. Thanks Rob

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width