Solved

Trouble exporting a Table when using my own methods.

Posted on 2008-11-01
7
197 Views
Last Modified: 2013-11-26
If I was able to do
Dim dt As New MyTable
    dt.Export.ToCSV()
Or even simpler
Dim dt As New MyTable
    dt.ExportToCSV()
When ever ExportToCSV is called, how does it know what table to export without me passing that table in?
0
Comment
Question by:rgn2121
  • 5
  • 2
7 Comments
 
LVL 12

Author Comment

by:rgn2121
ID: 22856097
TechTiger007:
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
0
 
LVL 12

Author Comment

by:rgn2121
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
0
 
LVL 12

Author Comment

by:rgn2121
ID: 22856108
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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.

Regards,

Wayne
0
 
LVL 12

Author Comment

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

Accepted Solution

by:
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.

Wayne
Public Class MyTable
    Inherits System.Data.DataTable 
    Sub New()
        MyBase.New()
    End Sub 
    Public Property Export() As ExportClass
        Get 
        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

0
 
LVL 12

Author Comment

by:rgn2121
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.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

17 Experts available now in Live!

Get 1:1 Help Now