Computing.Net > Forums > Programming > vb questions

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

vb questions

Reply to Message Icon

Name: Ken
Date: October 11, 2002 at 14:28:51 Pacific
OS: xp pro
CPU/Ram: duron650/256
Comment:

Hello, I am a newbie at programming and have started with VB. I created a simple windows utility as a project to clear temp files, cache, cookies, history, etc. I created command buttons for each operation, and it does clear out the files that I want when there are some there to delete. But, if the Cookies folder is already empty and I click the "Clear Cookies" button, it comes back with with file not found and closes. How can I tell it not to give that error if it's already empty. Thanks alot.

Ken



Sponsored Link
Ads by Google

Response Number 1
Name: Critter
Date: October 11, 2002 at 14:51:18 Pacific
Reply:

dim strFile as string

strFile=Dir("c:\")

if strFile "" then
end if


0

Response Number 2
Name: Critter
Date: October 11, 2002 at 14:53:00 Pacific
Reply:

dim strFile as string

strFile=Dir("c:\{location of cookie files}")

if strFile "" then
{code to delete files}
end if

Sorry, the in the first response I used angle brackets and they got interpreted as html codes.


0

Response Number 3
Name: Critter
Date: October 11, 2002 at 14:57:19 Pacific
Reply:

one more try...

if strFile {insert VB code for 'not equal'} "" then
{code to delete files}
end if

use the two angle brackets to represent 'not equal'... if I put them in the post, they get seen as html and don't show up


0

Response Number 4
Name: Ken
Date: October 11, 2002 at 17:04:54 Pacific
Reply:

Thanks, but what's the code for not equal?


0

Response Number 5
Name: Critter
Date: October 11, 2002 at 17:26:27 Pacific
Reply:

The less than sign immediately followed by the greater than sign (ie while holding down the shift key, press the comma, then the period).

I'm sure there's a way to type angle brackets in here without it getting interpreted as HTML... if anyone knows, please post a followup.


0

Related Posts

See More



Response Number 6
Name: Jeff J
Date: October 11, 2002 at 18:20:41 Pacific
Reply:

You need to use the HTML equivalents:

< = less-than
> = greater-than

Actually, the > symbols usually work; it's mostly the < symbols that cause problems, since they start tags.


0

Response Number 7
Name: Ken
Date: October 11, 2002 at 20:19:38 Pacific
Reply:

Ok, now it doesnt clear anything at all, but I get no errors when the directory is actually empty. Here's waht I have so far...

Private Sub Command3_Click()
strFILE = "c:\WINDOWS\Temp\*.*"
If strFILE = "" Then
Kill "C:\WINDOWS\Temp\*.*"
End If
MsgBox "Temp files deleted sucessfully"
End Sub

Thanks for the help...


0

Response Number 8
Name: Ken
Date: October 11, 2002 at 20:21:01 Pacific
Reply:

The code to for 'not equal to' is in ""


0

Response Number 9
Name: Critter
Date: October 11, 2002 at 23:09:29 Pacific
Reply:

You have...
strFILE = "c:\WINDOWS\Temp\*.*"

it should be
strFILE = Dir("c:\windows\temp")

After this call, if there are no files in the directory, then Dir will not return anything and strFILE will equal nothing ( ie strFILE=""). In this case, you don't run any file deletion code.

However, if there are files in the directory, then the first call to Dir will return the first file in the list and strFILE will contain that file name. In this case, you would run the file deletion code.

The easiest way to fix your code would be...

strFILE = Dir("c:\WINDOWS\Temp")

If strFILE = "" Then
Exit sub
Else
Kill "C:\WINDOWS\Temp\*.*"
MsgBox "Temp files deleted sucessfully"
End If


End Sub


0

Sponsored Link
Ads by Google
Reply to Message Icon

How do you skip lines in ... MDIform question



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: vb questions

2 VB Questions www.computing.net/answers/programming/2-vb-questions/3577.html

2 VB questions www.computing.net/answers/programming/2-vb-questions/3388.html

An easy VB question www.computing.net/answers/programming/an-easy-vb-question/929.html