+ Reply to Thread
Results 1 to 4 of 4

class functions

Hybrid View

  1. #1
    Registered User
    Join Date
    12-15-2005
    Posts
    23

    class functions

    i've programed classes in C++ where you can have functions that are specific to the class and have access to all the variables in the class.

    how would i need to setup a Sub that would have access to these variables?
    i want something along the lines of
    Private Sub DrawAddOne(ByVal a As Integer)
        m_Draw(a) = m_Draw(a) + 1
    End Sub

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello TheIrishThug,

    Unfortunately VBA is not a true object oriented language like C++. A VBA object does not inherit all the properities from a particular class when it is created. Programmers who use other OOLs that start to learn VB or VBA often assume that a Class is a Class. A Class object in VB or VBA is more like Java and nothing like a C or C++ class. I would suggest you read up on VB classes to gain a better understanding of their function and design. Wish I could be more help, but it isn't as simple as your example.

    Sincerely,
    Leith Ross

  3. #3
    Bob Phillips
    Guest

    Re: class functions

    Declare the variables as module level variables perhaps? That is, before any
    procedure declarations within the module.

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "TheIrishThug" <TheIrishThug.20ruga_1135809301.4345@excelforum-nospam.com>
    wrote in message
    news:TheIrishThug.20ruga_1135809301.4345@excelforum-nospam.com...
    >
    > i've programed classes in C++ where you can have functions that are
    > specific to the class and have access to all the variables in the
    > class.
    >
    > how would i need to setup a Sub that would have access to these
    > variables?
    > i want something along the lines of
    >
    > Code:
    > --------------------
    >
    > Private Sub DrawAddOne(ByVal a As Integer)
    > m_Draw(a) = m_Draw(a) + 1
    > End Sub
    >
    > --------------------
    >
    >
    > --
    > TheIrishThug
    > ------------------------------------------------------------------------
    > TheIrishThug's Profile:

    http://www.excelforum.com/member.php...o&userid=29682
    > View this thread: http://www.excelforum.com/showthread...hreadid=496534
    >




  4. #4
    Chip Pearson
    Guest

    Re: class functions

    Declare the variables in the declarations section of the class
    (before and outside of any procedure), and make you procedures
    Public not Private. E.g.,


    Private m_Draw(1 To Whatever) As Whatever

    Public Sub DrawAddOne(ByVal a As Integer)
    m_Draw(a) = m_Draw(a) + 1
    End Sub


    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com


    "TheIrishThug"
    <TheIrishThug.20ruga_1135809301.4345@excelforum-nospam.com> wrote
    in message
    news:TheIrishThug.20ruga_1135809301.4345@excelforum-nospam.com...
    >
    > i've programed classes in C++ where you can have functions that
    > are
    > specific to the class and have access to all the variables in
    > the
    > class.
    >
    > how would i need to setup a Sub that would have access to these
    > variables?
    > i want something along the lines of
    >
    > Code:
    > --------------------
    >
    > Private Sub DrawAddOne(ByVal a As Integer)
    > m_Draw(a) = m_Draw(a) + 1
    > End Sub
    >
    > --------------------
    >
    >
    > --
    > TheIrishThug
    > ------------------------------------------------------------------------
    > TheIrishThug's Profile:
    > http://www.excelforum.com/member.php...o&userid=29682
    > View this thread:
    > http://www.excelforum.com/showthread...hreadid=496534
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1