Link to home
Start Free TrialLog in
Avatar of riskyricky1972
riskyricky1972

asked on

COM / Class in VB.net/VB 6.0

I am a very beginning programmer to learn object-oriented programming...In VB 6.0, it is called OO, and VB.net called class i guess.
First, I hope someone can send me information or project-based books so I can study that.
Second, I hope to get clear what is real different between "Get" and "Let" in CLASS.

I will use VB.net / VB 6.0 to start as my programming tools...

Thank you for all your helps.

Avatar of InteractiveMind
InteractiveMind
Flag of United Kingdom of Great Britain and Northern Ireland image

Ricky,
I don't do VB myself, but:

  > "In VB 6.0, it is called OO, and VB.net called class"

OO = Object Oriented
..VB 6.0 is not Object Oriented; (whereas VB.Net is).

"class", at least in Java, C++, etc, is basically a way of defining an object.

Perhaps I'm just totally unfamiliar with VB talk ... but from what I can see, you've got your wires crossed.

Regards;
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tonym001
tonym001

VB6
As an example

Start a new project
Add class module to it and in properties window set name to clsTest
Two choices now either:
1:  In tools in menu options select Add Procedure, set name = value, type as property and scope as public
When code is created change
Public Property Get Value() As Variant to
Public Property Get Value() As Integer
and
Public Property Let Value(ByVal vNewValue As Variant) to
Public Property Let Value(ByVal vNewValue As Integer)

2. Type the above
 Insert the following in form

Option Explicit
Dim mTest As clsTest 'declare the type you just created
Private Sub Form_Load()
Dim Count1 As Integer
Set mTest = New clsTest 'initialise the class

For Count1 = 0 To 10
    mTest.Value = Count1 'set the value
    Debug.Print mTest.Value 'get the value
End Sub
In a Class, in order for a USER of that class to access the value of the property, the Property GET part is used.  This will return the value of the property.

When the USER of the class needs of assign a value to the property, the Property LET part is used, to assign the value TO the property.

As an example, let's say you have a Person Class, and that Class has a Name property.  You would then have code like this:

Public Class Person
   Private m_Name as String ' this is the CLASS variabl;e that will hold the Name VALUE

   Public Property Name() as String
       Get
           Return m_Name  ' sends back whatever happens to be the NAME of the current Person OBJECT
       End Get
       Set (byVal Value as String)
           m_Name = Value      ' saves whatever happens to be the name to be assigned to the current Person OBJECT
       End Set
   End Property
End Class


Now when you want to create a Person OBJECT ( anINSTANCE of this class), in your program:

Dim objPerson as New Person       ' create a new Person Object, using the class defined above

objPerson.Name = "Joe"    ' This object represents JOE, so we use the SET part of the Class, to assign the string "Joe" to the Name Property
.
.
.
    MessageBox.Show "The Current Person object is named " & objPerson.Name

' And here we want to retrieve the Name assigned to the Person object, so we use the GET part of the Class, to get back whatever had been stored as the Name.


This is a very simplified example, and you would probably never do anything this simple in a real program, but it was here to try to show the difference between the Get part and the Set/Let part of the Property.

AW

just to further confuse you, VB 6 DID allow you to create your own classes, and to use them ALMOST the same as you can in VB.NET - the differences were there, but it is NOT correct to imply that VB 6 did not allow you to create your own objects.  In very technical terms, VB 6 was Object-BASED, where VB.NET is Object ORIENTED. (Believe me, to try to fully explain the meaning of those two terms as used here is a discussion that I don't think you (riskyricky1972) would want to get into.)

AW