Results 1 to 4 of 4

Thread: Files not found

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Files not found

    I read the files from vb,
    How to pop up the messagebox when the files not found?

    Code:
    Dim txtVar1 As String
    Open App.Path + "\Data.txt" For Input As #1
    Input #1, txtVar1
    Close #1

  2. #2
    Lively Member
    Join Date
    Sep 2008
    Posts
    77

    Re: Files not found

    So you want the user to get a pop-up if it fails? Or are you getting this at debug?

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Files not found

    You have to check if the target file exists, here is one method....

    Code:
    Private Function CheckPath(Byval strPath As String) As Boolean
        If Dir$(strPath) <> "" Then
            CheckPath = True
        Else
            CheckPath = False
        End If
    End Function
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Files not found

    Quote Originally Posted by matrik02
    I read the files from vb,
    How to pop up the messagebox when the files not found?

    Code:
    Dim txtVar1 As String
    Open App.Path + "\Data.txt" For Input As #1
    Input #1, txtVar1
    Close #1
    Recommend pro-active methods similar to what Dee-U posted.
    What you posted is an example of a reactive method, allowing errors to occur to determine whether the file exists or not. The only thing missing is an On Error statement that would look like the following:
    Code:
         Dim txtVar1 As String
         On Error Goto FailedToOpen
         Open App.Path + "\Data.txt" For Input As #1
         Input #1, txtVar1
         Close #1
    FailedToOpen:
         If Err Then 
             MsgBox Err.Description
             Err.Clear
         End If
    End Sub
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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