Solved

How to shut my program down if I can load an xml document

Posted on 2008-10-29
5
134 Views
Last Modified: 2010-05-18
I want to exit out of my program the xml source file does not exist.


somthing like--
 

'Read from xml file

Try

XmlReader.Create(xmlLoc)

Catch ex As Exception

MessageBox.Show("Could not create file" & vbCrLf & ex.Message)

Finally

e.Cancel = True

End Try

Open in new window

0
Comment
Question by:gvilla23
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:xDJR1875
ID: 22836839
after the End Try

End
0
 

Author Comment

by:gvilla23
ID: 22836857
I have code after that so it gives me green squiggly lines after the End.
0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 22836869
Personally I would unload the main application form. I would not recommend terminating the application abruptly.

You will want to compare against your cancel value, otherwise the code suggested above will end your program whether the XML file was loaded or not.
'Read from xml file

Try

   XmlReader.Create(xmlLoc)

Catch ex As Exception

   MessageBox.Show("Could not create file" & vbCrLf & ex.Message)

Finally

   e.Cancel = True

End Try
 

If e.Cancel Then

   End

   ' Or better still uncomment the following line

   ' Unload Me

End If

Open in new window

0
 

Author Comment

by:gvilla23
ID: 22836922
I get a blue squiggly line under unload.
0
 
LVL 13

Accepted Solution

by:
numberkruncher earned 50 total points
ID: 22836936
Sorry, for some strange reason I thought you were using VB6.

You want to close the current form.

Me.Close

If you get a blue squiggly under that try just Close. You will have to excuse my VB2005+ skills.
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

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 47
Macro: print each sheet to pdf using ExportAsFixedFormat 11 40
Using "ScreenUpdating" 6 55
Access 2013 combo box not working 3 38
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
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…

911 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