ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   class functions (https://www.excelbanter.com/excel-programming/349071-class-functions.html)

TheIrishThug[_16_]

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

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


Leith Ross[_439_]

class functions
 

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


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=496534


Bob Phillips[_6_]

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"
wrote in message
news:TheIrishThug.20ruga_1135809301.4345@excelforu m-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




Chip Pearson

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"
wrote
in message
news:TheIrishThug.20ruga_1135809301.4345@excelforu m-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





All times are GMT +1. The time now is 08:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com