something wrong here in open file function
in a module i have this:
VB Code:
Public Function File_Exists(strFilePath As String)
If Dir(strFilePath, vbNormal + vbHidden + vbSystem + vbReadOnly) = "" Then
File_Exists = False
Else
File_Exists = True
End If
End Function
Public Function ShellOpenFile(filepath As String)
If (File_Exists(filepath)) Then
Shell "notepad filepath", vbNormalFocus
Else
MsgBox "No such file: " & filepath
End If
End Function
in my form1, i have this..
VB Code:
Private Sub Command2_Click()
ShellOpenFile ("C:\test.txt")
End Sub
but it keeps saying that 'filename.txt' doesnt exist :confused: :confused:
Re: something wrong here in open file function
VB Code:
Public Function File_Exists(strFilePath As String)
If Dir(strFilePath, vbNormal + vbHidden + vbSystem + vbReadOnly) = "" Then
File_Exists = False
Else
File_Exists = True
End If
End Function
Public Function ShellOpenFile(filepath As String)
If (File_Exists(filepath)) = true Then
Shell filepath , vbNormalFocus
Else
MsgBox "No such file: " & filepath
End If
End Function
VB Code:
Private Sub Command2_Click()
ShellOpenFile ("C:\test.txt")
End Sub
now try it
Re: something wrong here in open file function
that gives me:
invalid procedure call or argument on
line
Shell filepath, vbNormalFocus
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
Re: something wrong here in open file function
I could be wrong, but shouldn't:
VB Code:
If Dir(strFilePath, vbNormal + vbHidden + vbSystem + vbReadOnly) = "" Then
be
VB Code:
If Dir(strFilePath, vbNormal Or vbHidden Or vbSystem Or vbReadOnly) = "" Then
Re: something wrong here in open file function
Quote:
Originally Posted by longwolf
I could be wrong, but shouldn't:
VB Code:
If Dir(strFilePath, vbNormal + vbHidden + vbSystem + vbReadOnly) = "" Then
be
VB Code:
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. :wave:
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. :wave:
humm, your right
They both came up with 7