Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a 'sub' Method

Status
Not open for further replies.

KLK000

MIS
May 22, 2002
37
US
I'm creating a Class that performs low level manipulation of an archaic indexed sequential database. The Class is to make it easier for other developers who have to manipulate this database. I have a Class with Properties and Methods (subs and functions). However, how do I create a sub-method (a method under a method). As an example. I want the developer to be able to access a method in my class as follows:

MyClass.Method1

This I can program with no problem.

However, I also want the developer to access a sub-method as follows:

MyClass.Method1.SubMethod1

Any examples of how this can be programmed would be greatly appreciated.

 
To do that, you need a class with in your class.
Pardon my sample. I am typing off the the top of my head here so there is no syntax checking. Its just to give you an idea.

Class2
Public Function ReadDBType1(recno as short) as string
' do your stuff
end function
end class


Class 1
public ReadDB as new Class2
Public Function MyStuff() as short
' whatever
end function
end class

In your program:
dim MyClass as new Class1

You can then perform MyClass.MyStuff
and you can call MyClass.ReadDB.ReadDBType1(4)

I hope that clarifies it for you.
 
The items that shows up at your "SubMethod1" level are actually the members and methods of the object type returned by Method1.

For example, if MyClass has a function GetData that returns a datatable, you could do this:

MyClass.GetData.Rows.Add(datarow)

If you have a specific list of custom members you want to be available, create a class that contains those subs/functions/properties and make that the return type of your Method1 on MyClass.

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Thanks all. I had experimented with this approach but I wasn't sure this was the way it's supposed to be done. I'll proceed with more confidence now.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top