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 wOOdy-Soft 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 new VB Class

Status
Not open for further replies.

gollie

Programmer
Jun 20, 2003
3
ZA
I have been building some small Systems using VB6 without using CLASSES but now Iam faced with a Situation where by i have to build a Very big System and I want to use classes, I have built some classes using Class wizard but now now i can't refer to them, I hope my message is Clear now!

Can somebody help me with just how to start this!
 
I havent created any classes with the wizard before, but you may want to look at whether they are decared public, private etc... They should be public to be called from anywhere else in the project
 
You might want to look into a couple of books:

Visual Basic Object and Component Handbook

Building N-Tier Applications with COM and Visual Basic 6.0

Be advised that both are intermediate to advanced level books, so you should already be familiar with the mechanics of how Visual Basic works (you should know the difference between public methods and private methods, how to call one class from another class, etc).

Chip H.

____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Your classes will exist as .CLS files.

Just as when you wish to re-use a form or module, you can add an existing CLS file to your project.

If you save your CLS files in one common folder, this will allow you to share them between projects.

Whether the class is public or private is not really relevant here, as it will simply become part of your larger project.
This is a 'shared code' approach.


It is possible to use CLS file as the basis for an OLE DLL, which you can compile using VB, and then add to your project/s as a reference.

This has the advantage of keeping your compiled file size down, and means that a change to the DLL code will 'fix' all of your apps that use it, without needing to recompile them.

 
Thanx every1 for your continual comments,

I'm gonna use them hope they'll be effective!I think the classes are Public though!

But the thing is, after creating the Classes using the VB Class Builder Wizard, I was even able to give Properties to the Classes, eg. for Class Employee properties will be Employee_name, Employee_ID etc, The main problem is setting new instances of such classes, ie, how do I set it for new instances to take properties of such class!

Thanx every1!

Gollie

Iam gonna check on the books Chiph!
 
gollie,
You might want to take a look at this tutorial:

Visual Basic Tutorial - Very nice!

You shouldn't have a problem instanciating objects of your classes. An object variable is created the same way a string or an integer variable is. When you create a class (either manually or through the class Wizard), the class is detected by IntelliSense and is listed in the list of options that comes up after you type "As" when declaring a variable. Like this:
Code:
[green]' This way...[/green]
[blue]Dim[/blue] yourObject [blue]As[/blue] [b]YourClass[/b]
[green]' Or like this...[/green] 
[blue]Dim[/blue] yourObject [blue]As New[/blue] [b]YourClass[/b]
In the code above, YourClass is, of course, the name that you give to your class.

In terms of a book, you might also want to take a look at Programming Visual Basic 6.0 which is one of the best (if not the best) VB6 books out there.

JC


_________________________________________________
To get the best response to a question, read faq222-2244.
 
But the thing is, after creating the Classes using the VB Class Builder Wizard, I was even able to give Properties to the Classes, eg. for Class Employee properties will be Employee_name, Employee_ID etc, The main problem is setting new instances of such classes, ie, how do I set it for new instances to take properties of such class!<<

If your class has a property called Employee_Name, then
when you create an instance of the class using

dim MyObject as New MyClass

MyObject becomes a 'working example' of the class.
It will have all the public properties you gave to the class, but none of the private properties will be visible.
eg You will be able to use MyObject.Employee_Name


Public V Private properties:
You might create a 'Piggy Bank' class
It has an 'Add Money' function, and a 'Total Value' property.
These are public. The Total Value property is only declared with a Get function, not a Let, and so is read-only.

It also has a 'Value' property, which holds the actual amount of cash contained. But this is private.

You do this so that no-one can affect the money in the bank simply by doing MyObject.Value = 6 billion pounds

Instead, they have to use MyObject.AddMoney (some value)
This affects the private Value property.
If you want to know how much is in there, you interrogate the TotalValue property, which is safe.

This 'hiding' of stuff that should not be changeable directly is more commonly known as encapsulation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top