|
-
Mar 9th, 2007, 12:14 PM
#1
Thread Starter
Lively Member
kill file
Code:
Private Sub mnuFileList_Click(Index As Integer)
If Index = 1 Then
Kill App.Path & "/Data.txt"
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
End If
End Sub
i want the program always kill file "data.txt" when press the menu if the "data.txt" is present.
But, i got the error "file not found"(because data.txt not present) with the code above. How to improve the code above to let it kill file when the data.txt is present.
-
Mar 9th, 2007, 12:20 PM
#2
Re: kill file
Code:
Private Sub mnuFileList_Click(Index As Integer)
If Index = 1 Then
If Dir$(App.Path & "/Data.txt") <> vbNullString Then 'it exists - kill it
Kill App.Path & "/Data.txt"
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
End If
End If
End Sub
-
Mar 9th, 2007, 12:22 PM
#3
Re: kill file
Check the directory to see if DIR$("FileName") is a not a null. If it is not, then you can safely kill the file. If it is a null and you then try to kill it, that generates the error. The correct statement in one line is thus
Code:
IF Dir$(FilePathName$)<> "" Then Kill FilePathName$
-
Mar 9th, 2007, 12:32 PM
#4
Thread Starter
Lively Member
Re: kill file
What difference between vbNullString and ""?
-
Mar 9th, 2007, 12:39 PM
#5
Re: kill file
 Originally Posted by junlo
What difference between vbNullString and ""?
Memory allocation.
"" has a length of 0 but still takes up memory. vbNullString requires no memory.
Here is a brief tutorial.
-
Mar 9th, 2007, 12:40 PM
#6
Addicted Member
Re: kill file
dim nPath as string
nPath = "c:\folder\"
If Len(Dir(nFolder & "\filename.txt")) <> 0 Then
kill
End If
-
Mar 9th, 2007, 12:41 PM
#7
Re: kill file
In this case none, and you can use > "", since it can't ever be < "".
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Mar 9th, 2007, 01:05 PM
#8
Re: kill file
This might also work:
Code:
If Len(Dir$(PathFileName$)) THEN KILL PathFileName$
'implication not zero and no string comparison required
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
|