Solved

vbscrpit end program

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

939 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

16 Experts available now in Live!

Get 1:1 Help Now