|
-
Oct 19th, 2005, 03:44 PM
#1
Thread Starter
Frenzied Member
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
-
Oct 19th, 2005, 03:57 PM
#2
Frenzied Member
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
-
Oct 19th, 2005, 05:06 PM
#3
Thread Starter
Frenzied Member
Re: something wrong here in open file function
that gives me:
invalid procedure call or argument on
line
Shell filepath, vbNormalFocus
-
Oct 19th, 2005, 05:20 PM
#4
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
-
Oct 19th, 2005, 10:51 PM
#5
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
-
Oct 19th, 2005, 11:14 PM
#6
Re: something wrong here in open file function
 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.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Oct 20th, 2005, 12:39 AM
#7
Re: something wrong here in open file function
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|