Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default "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/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default "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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default "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/

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Select method of Range class failed" Error Ayo Excel Discussion (Misc queries) 3 September 2nd 08 07:58 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Run-time error "1004" Select method of range class failed Tallan Excel Discussion (Misc queries) 3 March 7th 07 05:22 PM
VBE - Possible to have one of five modules in a VB project to be "default"? [email protected] Excel Discussion (Misc queries) 2 September 22nd 06 09:58 PM
"Unable to set the Formula property of the Series class" with a tw PeterQ Charts and Charting in Excel 1 February 15th 06 07:37 PM


All times are GMT +1. The time now is 09:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"