?
Solved

calling custom class from vb.net app

Posted on 2005-05-04
6
Medium Priority
?
246 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:k3n51mm
6 Comments
 
LVL 7

Expert Comment

by:rohanbairat3
ID: 13930716
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
 
LVL 1

Author Comment

by:k3n51mm
ID: 13931077
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
 
LVL 4

Expert Comment

by:Excalibur_Software
ID: 13931945
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:k3n51mm
ID: 13932370
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
 
LVL 8

Expert Comment

by:rodmjay
ID: 13933609
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
 
LVL 8

Accepted Solution

by:
rodmjay earned 1500 total points
ID: 13933622
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Integration Management Part 2
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month17 days, 2 hours left to enroll

864 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