Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Exposing Class Module from VBA Excel 97 SR-2

I've created some class modules in an Excel 97 project (a unit testing
framework) which I would like to expose as a library to other projects
(the workbooks which I want to test).

From the advice I've read so far, I've created a factory module in the
library which returns objects:

Public Function TestManager() As TestManager
Set TestManager = New TestManager
End Function

which means that the calling code can do something like the following:

Option Explicit
Public Test As Object

Sub runTests()
Set Test = UnitTestFactory.TestManager ' defined in library project
Test.addSuite New QSheet_Test ' defined in this project
Test.run
End Sub

This works... but the main annoyance is that there are a large number
of methods used in the test fixtures, and as the library's class modules
(including TestManager) aren't exposed, the VBE can't prompt with all
the utility methods (AssertTrue etc.).

Sub run()
Test.AssertTrue 2 1
Test.AssertEquals 100, 100
Test.AssertNotEquals 100, "a sheep"
Test.AssertIsNotNothing SomeObjectRef
Test....
End Sub

This makes the library less friendly: and I want to minimize any
possible excuses to *not* unit test!

I've seen advice (mainly re Access) to Export and re-Import the .cls
file changing the line:

Attribute VB_Exposed = False
- Attribute VB_Exposed = True

but this doesn't work for me. (When I export the class again, the
line has been reset to VB_Exposed = False).

Any suggestions gratefully received!

osfameron
--
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Exposing Class Module from VBA Excel 97 SR-2

You can change the instancing property of the class to PublicNotCreateable
and declare the variable as that class type rather the as Object. E.g.,

Dim Test As UnitTestFactory.TestManager


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



"hakim" wrote in message
om...
I've created some class modules in an Excel 97 project (a unit testing
framework) which I would like to expose as a library to other projects
(the workbooks which I want to test).

From the advice I've read so far, I've created a factory module in the
library which returns objects:

Public Function TestManager() As TestManager
Set TestManager = New TestManager
End Function

which means that the calling code can do something like the following:

Option Explicit
Public Test As Object

Sub runTests()
Set Test = UnitTestFactory.TestManager ' defined in library project
Test.addSuite New QSheet_Test ' defined in this project
Test.run
End Sub

This works... but the main annoyance is that there are a large number
of methods used in the test fixtures, and as the library's class modules
(including TestManager) aren't exposed, the VBE can't prompt with all
the utility methods (AssertTrue etc.).

Sub run()
Test.AssertTrue 2 1
Test.AssertEquals 100, 100
Test.AssertNotEquals 100, "a sheep"
Test.AssertIsNotNothing SomeObjectRef
Test....
End Sub

This makes the library less friendly: and I want to minimize any
possible excuses to *not* unit test!

I've seen advice (mainly re Access) to Export and re-Import the .cls
file changing the line:

Attribute VB_Exposed = False
- Attribute VB_Exposed = True

but this doesn't work for me. (When I export the class again, the
line has been reset to VB_Exposed = False).

Any suggestions gratefully received!

osfameron
--



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Exposing Class Module from VBA Excel 97 SR-2

Oops, I forgot that Excel97 doesn't support PublicNotCreateable class
instancing. Ignore my reply.


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


"Chip Pearson" wrote in message
...
You can change the instancing property of the class to PublicNotCreateable
and declare the variable as that class type rather the as Object. E.g.,

Dim Test As UnitTestFactory.TestManager


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



"hakim" wrote in message
om...
I've created some class modules in an Excel 97 project (a unit testing
framework) which I would like to expose as a library to other projects
(the workbooks which I want to test).

From the advice I've read so far, I've created a factory module in the
library which returns objects:

Public Function TestManager() As TestManager
Set TestManager = New TestManager
End Function

which means that the calling code can do something like the following:

Option Explicit
Public Test As Object

Sub runTests()
Set Test = UnitTestFactory.TestManager ' defined in library

project
Test.addSuite New QSheet_Test ' defined in this project
Test.run
End Sub

This works... but the main annoyance is that there are a large number
of methods used in the test fixtures, and as the library's class modules
(including TestManager) aren't exposed, the VBE can't prompt with all
the utility methods (AssertTrue etc.).

Sub run()
Test.AssertTrue 2 1
Test.AssertEquals 100, 100
Test.AssertNotEquals 100, "a sheep"
Test.AssertIsNotNothing SomeObjectRef
Test....
End Sub

This makes the library less friendly: and I want to minimize any
possible excuses to *not* unit test!

I've seen advice (mainly re Access) to Export and re-Import the .cls
file changing the line:

Attribute VB_Exposed = False
- Attribute VB_Exposed = True

but this doesn't work for me. (When I export the class again, the
line has been reset to VB_Exposed = False).

Any suggestions gratefully received!

osfameron
--





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Exposing Class Module from VBA Excel 97 SR-2


You can change the instancing property of the class to
PublicNotCreateable and declare the variable as that
class type rather the as Object. E.g.,

Dim Test As UnitTestFactory.TestManager


Chip,

Thanks: I remember seeing that same advice, but in Excel 97
SR 2 I can't see a way to change the instancing property doing
any of:

- in Properties window for class: only property is "(Name)"
- in VBAProject properties
- Option keyword?
- editing the .cls file out of desperation and changing the line
MultiUse = -1 to read PublicNotCreateable = -1

Thanks again!
osfameron


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly 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
Creating UDF by Class Module (Leo)? Leo Excel Discussion (Misc queries) 1 December 2nd 08 10:59 AM
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM
please give an example of a class module. Mike[_33_] Excel Programming 1 July 24th 03 07:27 AM
how to declare a class module Kevin Excel Programming 5 July 15th 03 01:04 AM


All times are GMT +1. The time now is 11:49 PM.

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

About Us

"It's about Microsoft Excel"