Solved

vbscrpit end program

Posted on 2004-08-26
4
129 Views
Last Modified: 2010-05-02
I want to use a
If Err.number <> 0 then
             end
end if

I want to do something of this manner in VBscript. It doesn't let me do it. I have to end the program if it doesn't find the file. I dn't know how to do it. Please help. Thank you. This is a one liner, I guess.
0
Comment
Question by:parikht
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 11904001
>> I have to end the program if it doesn't find the file.

You can check for the existence of a file like this:

    Dim fileName As String
   
    fileName = "c:\somefile.txt"
    If Dir(fileName) <> "" Then
        ' do something with filename in here...      
    Else
        MsgBox fileName, vbCritical, "File not found"
    End If

Hope that helps you,

Idle_Mind
0
 
LVL 76

Expert Comment

by:David Lee
ID: 11914465
Do you mean something like this?  This will check for the existence of a file and terminate the script if it doesn't find it.

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("File path and name") Then
    'Do something with the file
Else
    Wscript.Quit
End If
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12398546
Recommend accepting Idle_Mind's response.  His was first.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now