Thread: Dim vs. Public
View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Dim vs. Public

"Jamie Collins" wrote in message
oups.com...

Bob Phillips wrote:

The thing you cannot do is share a variable between modules in this

way

It is possible e.g. this in (standard) Module1:

Option Explicit

Private m_strName As String

' Name can only be set internally
Private Function SetName( _
ByVal NewName As String _
) As Boolean
m_strName = NewName
End Function

' Name can be read externally
Public Property Get Name() As String
Name = m_strName
End Property

Then this another standard module:

Sub test()
MsgBox Module1.Name
End Sub

But ...


Yes, but I did say in this way (that is the Property way). This may work,
but it is another way <vbg

Excellent idea <vbg. For me the examples which sink ActiveX events
helped me most when trying to get my head around classes because, as
you say, the value is immediately apparent. Also, the ones that
encapsulate seemingly nasty APIs e.g. Stephen Bullen's CFormChanger and
FormFun demo is still the ultimate for me.


I agree. The dichotomy kicks in again though, as most people learning
classes, or wantintg to learn about classes, would probably not understand
such complexities. For an exercise in selling classes, I think an Excel
based example would be good. I know nothing about charting in Excel (I hate
Excel charts!), but I bet there is potential there for a good class to show
their use.

The paradox seems to be that
one needs to know what a class is for before it can seen as a real
solution but there's no incentive to learn until one has a suitable
problem.


The old Catch-22.

I've often tried to start a discussion on what exactly ThisWorkbook is
(last time I tried I think I caused offence - must be a sensitive issue
<g). Is it a class, an instance of a class, an interface, ...? It is
quite unlike any class I can write using class modules. I know I like
it because I can add new members (properties and methods) to
ThisWorkbook and so I use for things deemed to be workbook level i.e. a
lot.


Interesting. I need to email you offline on another topic, but I will
continue this a little in that as well. Can you also give the URL for that
discussion (hope it isn't the one on Ken Getz's article <ebg) so that I can
read your thoughts.


Interesting thread Jamie, thanks.