Results 1 to 7 of 7

Thread: something wrong here in open file function

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    something wrong here in open file function

    in a module i have this:

    VB Code:
    1. Public Function File_Exists(strFilePath As String)
    2.     If Dir(strFilePath, vbNormal + vbHidden + vbSystem + vbReadOnly) = "" Then
    3.         File_Exists = False
    4.     Else
    5.         File_Exists = True
    6.     End If
    7. End Function
    8.  
    9. Public Function ShellOpenFile(filepath As String)
    10.     If (File_Exists(filepath)) Then
    11.         Shell "notepad filepath", vbNormalFocus
    12.     Else
    13.         MsgBox "No such file: " & filepath
    14.     End If
    15. End Function

    in my form1, i have this..

    VB Code:
    1. Private Sub Command2_Click()
    2.     ShellOpenFile ("C:\test.txt")
    3. End Sub

    but it keeps saying that 'filename.txt' doesnt exist

  2. #2
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: something wrong here in open file function

    VB Code:
    1. Public Function File_Exists(strFilePath As String)
    2.     If Dir(strFilePath, vbNormal + vbHidden + vbSystem + vbReadOnly) = "" Then
    3.         File_Exists = False
    4.     Else
    5.         File_Exists = True
    6.     End If
    7. End Function
    8.  
    9. Public Function ShellOpenFile(filepath As String)
    10.     If (File_Exists(filepath)) = true Then
    11.         Shell filepath , vbNormalFocus
    12.     Else
    13.         MsgBox "No such file: " & filepath
    14.     End If
    15. End Function

    VB Code:
    1. Private Sub Command2_Click()
    2.     ShellOpenFile ("C:\test.txt")
    3. End Sub
    now try it

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: something wrong here in open file function

    that gives me:

    invalid procedure call or argument on

    line

    Shell filepath, vbNormalFocus

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: something wrong here in open file function

    The problem is in this line: Shell "notepad filepath", vbNormalFocus

    The problem is that filepath is inside the quotes, so you are passing the text filepath rather than the contents of it (C:\test.txt). What you should use instead is:

    Shell "notepad " & filepath, vbNormalFocus

  5. #5
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: something wrong here in open file function

    I could be wrong, but shouldn't:
    VB Code:
    1. If Dir(strFilePath, vbNormal + vbHidden + vbSystem + vbReadOnly) = "" Then
    be
    VB Code:
    1. If Dir(strFilePath, vbNormal Or vbHidden Or vbSystem Or vbReadOnly) = "" Then

  6. #6
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: something wrong here in open file function

    Quote Originally Posted by longwolf
    I could be wrong, but shouldn't:
    VB Code:
    1. If Dir(strFilePath, vbNormal + vbHidden + vbSystem + vbReadOnly) = "" Then
    be
    VB Code:
    1. If Dir(strFilePath, vbNormal Or vbHidden Or vbSystem Or vbReadOnly) = "" Then
    In this case Or and + are synonomous. eg 1 Or 2 = 3, as does 1 + 2. Try it.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  7. #7
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: something wrong here in open file function

    Quote Originally Posted by pnish
    In this case Or and + are synonomous. eg 1 Or 2 = 3, as does 1 + 2. Try it.
    humm, your right
    They both came up with 7

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