ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   "Static" Methods in Class Modules (https://www.excelbanter.com/excel-programming/287607-static-methods-class-modules.html)

Ripan[_3_]

"Static" Methods in Class Modules
 
Is there anyway to create static methods in VBA Class Modules. By this I
mean methods that can be accessed from outside the Class Module without
making an instance of the object.

As a more concrete example:

I have a class module to hold a Time (a value for hour, minute, and
AM/PM). I declare various variables that are instances of the Time
object. I want to see if one time is before another but I do not
necessarily want to have to create an instance of a Time Object to do
that. (I want to be able to call functions by using Time.x as you can
do in regular Methods).

I know this is possible in the C# and C++ frameworks through the use of
Static Methods. Is it possible in VBA?

Thanks for any help.


---
Message posted from http://www.ExcelForum.com/


solex

"Static" Methods in Class Modules
 
Ripan,

I am new to excel programming but have been programming VB for quite some
time, with that said I would assume that it is not possible to create a
static class method in VBA since the Global Multi Use (GMU) option is not
available for the instancing property of a class.

You could how ever create the method in a module and simply use
module.method syntax as you suggested below.

Dan

"Ripan " wrote in message
...
Is there anyway to create static methods in VBA Class Modules. By this I
mean methods that can be accessed from outside the Class Module without
making an instance of the object.

As a more concrete example:

I have a class module to hold a Time (a value for hour, minute, and
AM/PM). I declare various variables that are instances of the Time
object. I want to see if one time is before another but I do not
necessarily want to have to create an instance of a Time Object to do
that. (I want to be able to call functions by using Time.x as you can
do in regular Methods).

I know this is possible in the C# and C++ frameworks through the use of
Static Methods. Is it possible in VBA?

Thanks for any help.


---
Message posted from http://www.ExcelForum.com/




patrick molloy

"Static" Methods in Class Modules
 
To "use" a class module you'd need to instantiate it.
You can use variables and declare them as Static. Also
you can define your own Type
However, as an alternative, to could save your "times"
into a scripting.dictionary - set a reference to
scripting runtime). It looks and feels like a collection
but it also has a .Exists() method that returns a boolean
if the key exists or not.

Patrick Molloy
Microsoft Excel MVP
-----Original Message-----
Is there anyway to create static methods in VBA Class

Modules. By this I
mean methods that can be accessed from outside the Class

Module without
making an instance of the object.

As a more concrete example:

I have a class module to hold a Time (a value for hour,

minute, and
AM/PM). I declare various variables that are instances

of the Time
object. I want to see if one time is before another but

I do not
necessarily want to have to create an instance of a Time

Object to do
that. (I want to be able to call functions by using

Time.x as you can
do in regular Methods).

I know this is possible in the C# and C++ frameworks

through the use of
Static Methods. Is it possible in VBA?

Thanks for any help.


---
Message posted from http://www.ExcelForum.com/

.



All times are GMT +1. The time now is 08:19 AM.

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