COM / Class in 6.0

Posted on 2005-04-30
Last Modified: 2013-11-25
I am a very beginning programmer to learn object-oriented programming...In VB 6.0, it is called OO, and 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 6.0 to start as my programming tools...

Thank you for all your helps.

Question by:riskyricky1972
    LVL 25

    Expert Comment

    I don't do VB myself, but:

      > "In VB 6.0, it is called OO, and 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.

    LVL 52

    Accepted Solution

    Actually, VB6 is object-oriented, but in a fairly limited fashion, its certainly not fully object oriented in the way the C++ is.
    Although VB.Net is technically the next version of VB it has some pretty major differences.

    Both VB6 and VB.Net have classes, and they both have the same purpose - to define a template for objects. VB6 has three types of property methods - Get, Let and Set.
    Get is used to return the value of a property, Let is used to set the value of the property for an intrinsic type, Set is used to set a property that is an object.

    VB.Net supports properties, but in a slighly different, and simpler, way than VB6.
    LVL 2

    Expert Comment

    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
    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
    LVL 2

    Expert Comment

    LVL 44

    Expert Comment

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


    LVL 44

    Expert Comment

    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.)


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    734 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

    23 Experts available now in Live!

    Get 1:1 Help Now