?
Solved

vbscrpit end program

Posted on 2004-08-26
4
Medium Priority
?
138 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 200 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

741 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