Trouble exporting a Table when using my own methods.

Posted on 2008-11-01
Last Modified: 2013-11-26
If I was able to do
Dim dt As New MyTable
Or even simpler
Dim dt As New MyTable
When ever ExportToCSV is called, how does it know what table to export without me passing that table in?
Question by:rgn2121
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
  • 5
  • 2
LVL 12

Author Comment

ID: 22856097
ExportToCSV will be called on an object of MyTable which itself is a datatable.
Inside your Export method get the base class of the object which is a datatable and perform the operation on this object
LVL 12

Author Comment

ID: 22856098
That is what I am not sure about...Normally I pass in a destination file path of where it is to be exported and the table to export.

Sub ExportToCSV()

...Some Code

End Sub
LVL 12

Author Comment

ID: 22856108
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 22856129
Hi rgn2121,

When calling a method of an object (in this case, a MyTable object, which inherits from DataTable), you can access the underlying DataTable using the "Me" keyword.


LVL 12

Author Comment

ID: 22856137
What if I use your nested class example?  Me would then refer to the ExportClass correct?
LVL 47

Accepted Solution

Wayne Taylor (webtubbs) earned 500 total points
ID: 22856151
>>Me would then refer to the ExportClass correct?

Yes, if used in the ExportClass class. To "attach" a table to the ExportClass, pass it with the New procedure, as below.

The question I have though, is do you really need the ExportClass? Probably not. I'd simply have an ExportToCSV() routine in the MyTable class.

Public Class MyTable
    Inherits System.Data.DataTable 
    Sub New()
    End Sub 
    Public Property Export() As ExportClass
        End Get
        Set(ByVal value As ExportClass)
            value.Table = Me
        End Set
    End Property 
    Public Class ExportClass
        Public Table As MyTable
        Public Sub New(ByVal mt As MyTable)
            Me.Table = mt
        End Sub
        Public Function ToCSV() As Boolean
            'export the table "Table"
        End Function
    End Class 
End Class

Open in new window

LVL 12

Author Comment

ID: 22856160
>>The question I have though, is do you really need the ExportClass? Probably not. I'd simply have an >>ExportToCSV() routine in the MyTable class.

No...I was just curious...I really do appreciate all the help...Thanks.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 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 …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

697 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