Solved

vbscrpit end program

Posted on 2004-08-26
4
136 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

691 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