calling custom class from vb.net app

I have created a custom class which parses an xml document and writes a converted text file to the same directory.

I created a Convert() subroutine in the class which does the actual reading and extraction. I call the subroutine from within the New() constructor since the class is rather simple. It's my (way too inexperienced) understanding that the New() sub gets called each time an instance of the class is created from within the calling application. Is this true?

It doesn't appear to be working however. Before I write a million msgboxes for debug, I thought I would ask if the way I am approaching this is fundamentally flawed in some way. I mean is, is it okay to call the sub which actually does the work from the New() constructor?

Thanks
LVL 1
k3n51mmAsked:
Who is Participating?
 
rodmjayConnect With a Mentor Commented:
Throw New Exception(Message)
: this is what the syntax will be in the class

You may want to consider creating a new inherited exception class and throw that to the application with a custom signature for example with field in error and message for example.
0
 
rohanbairat3Commented:
Yes , you can do all that. But the purpose of constructors is to initialize the objects. It is all ways better to have it as a seperate method and call the method with the object of that class. IF you want this to be a singleton then the approach is different.

What part is not working in your code. ?

-Rons
0
 
k3n51mmAuthor Commented:
Here's the  new() sub. szSeddFile below is a global string. The extractA1() sub below is
being called but does not create output.

Also, what is a singleton?  

Public Sub New(ByVal xmlFile As String)

        Dim rdrSEDD As XmlTextReader = New XmlTextReader(xmlFile)
        Dim rdrVal As New XmlValidatingReader(rdrSEDD)
        rdrVal.ValidationType = ValidationType.DTD
        'create event handler for events raised by validator
        AddHandler rdrVal.ValidationEventHandler, AddressOf valEvtHandler
        ' Check whether the document is valid or invalid.
        If isValid Then
            'if successful, perform extraction, write A1 file to disk.
            szSeddFile = seddFile
            extractA1(szSeddFile)
        End If

    End Sub
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Excalibur_SoftwareCommented:
Without knowning what your class is call I'm thinking you are not creating the object from your class

Dim myObject as New the_name_of_your_class
Dim mytestData as string

mytestData = myObject.Convert(Your data)
0
 
k3n51mmAuthor Commented:
Actually I have now changed the code. I have made the procedure in the class a boolean function, and it is now returning a value of true or false depending on whether execution completes or not. I believe that the parsing routine is failing and raising an exception.

To hijack my own thread, I have the followiong question, now that the dynamics of the problem have changed somewhat:

How do I trap an exception in an external .dll such as this custom class module, and return the exception to the calling application?

thanks
0
 
rodmjayCommented:
Use try catch in the form and throw an error in the Class.  Do not use any try catches in the class at all.  Not even for dataconnections.  The app will then handle all thrown errors.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.