Solved

vbscrpit end program

Posted on 2004-08-26
4
135 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 86

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

733 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