Solved

Using MyBase, MyClass?

Posted on 2009-03-29
7
317 Views
Last Modified: 2012-05-06
Hi EE,

I am very new to .net and have created a class that handles all inserts, updates, deletes, etc. for all my lookup tables.
I have enumerated all my tables and defined how many fields they have and the types of fields and then by sending in the table name it creates the insert, update etc. for me.
This class inherits my Basic connection class.
All of this is working.
I am now building a class that will build grids according to what I have specified in my lookup class.  i.e number of columns, field type etc.
I have inherited the lookup class in this new class, but it keeps saying that I need a sub new and it needs to start with mybase or myclass.
The lookup class has a sub new that brings in the connection string and tablename but this class doesn't need a connection to the db.
What is the mybase and myclass and how do I use it?
Thanks
0
Comment
Question by:Sheritlw
  • 4
  • 3
7 Comments
 
LVL 4

Expert Comment

by:freer
ID: 24014273
> The lookup class has a sub new that brings in the connection string and tablename but this class
> doesn't need a connection to the db

This suggests that you don't want to inherit from the lookup class.

MyBase is a way to call the methods of the base class (from which you inherit) in the sub class (your new class).

MyClass is a way to call the methods of the current class in a way that cannot be overridden.

Tim
0
 
LVL 4

Expert Comment

by:freer
ID: 24014291
See here for the official explanation:

http://msdn.microsoft.com/en-us/library/c8shwxa5(vs.71).aspx

The reason I'm suggesting inheritance is inappropriate here is that normally you inherit because you want a more specialized version of the same thing. Eg. you might have a class Person and inherit from it in the class Employee. However if your new class doesn't need a connection, it sounds like it is a different thing completely, not a more specialized version of the same thing.

Tim
0
 

Author Comment

by:Sheritlw
ID: 24014303
That makes since.
If I take out inheritance, how can I easily use all the properties/functions etc. in the lookup class?
Thanks
0
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.

 
LVL 4

Expert Comment

by:freer
ID: 24014336
You can either have a reference to an instance of the lookup class and call its members. Or you can make the methods of the lookup class shared in which case you can call them without an object instance.

Tim
0
 

Author Comment

by:Sheritlw
ID: 24014378
I changed one of the functions to shared which has a select case for the table names.  It says I cannot refer to an instance member of a class with a shared method etc.
How do I handle that?
Thanks,
0
 
LVL 4

Accepted Solution

by:
freer earned 500 total points
ID: 24014438
A shared method belongs to the class, not to an instance of the class. Therefore you can't call members of the current instance in a shared method - as far as the shared method is concerned, there is no current instance. You'll therefore generally find yourself either making most of the methods in a class shared, or most of them not shared.

I think you would benefit from taking some time out to read up on objects and classes in VB as its important to figure this out.

Tim

0
 

Author Comment

by:Sheritlw
ID: 24014462
Yes, I agree.  I have been reading and reading for weeks now and still struggling.  It's so different than VB 6, but I will learn.
Thanks for the info... it was good.
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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 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

12 Experts available now in Live!

Get 1:1 Help Now