Last week Jonathan, Karl, and Jean-Guy where schooling me on Class
modules. I have read the articles that Jonathan posted and wanted to
try to put theory to practice.

Submitted for comments by those or any other master.

With the input of a few others, I have put together a routine that
ensures the input to a VBA input box is a numeric whole number greater
than five. It is several lines of code and I thought perhaps that it
could be a "Class" and if I need a whole number greater than 5 several
times in a procedure that I could call the class.

Here is my testing procedure:

Sub TestOfClass()
Dim myNum As myNumClass
Dim i As Long
Set myNum = New myNumClass
For i = 1 To myNum.lngNumber
Debug.Print "Test1"
Next i
Set myNum = New myNumClass
For i = 1 To myNum.lngNumber
Debug.Print "Test2"
Next i
End Sub

I created a Class named myNumClass and entered this code:

Private mLngNumber As Long
Private Sub Class_Initialize()
Dim strInput As String
Dim bInValid As Boolean
Do
bInValid = False
strInput = InputBox("Enter a whole number greater than 5", _
"Number Input", "0")
If strInput = vbNullString Then Exit Sub
On Error Resume Next
If strInput <> CLng(strInput) Or CLng(strInput) <= 5 Then
If Err.Number = 13 Then
bInValid = True
On Error GoTo 0
Else
bInValid = True
End If
End If
If bInValid Then
MsgBox "You must enter a valid whole number that is > 5."
End If
Loop While bInValid
mLngNumber = strInput
End Sub
Property Get lngNumber() As Long
lngNumber = mLngNumber
End Property

When I run TestofClass, I see the results that I expect. My questions
are:

1. Is this a sensible use of a class?
2. Is it constructed in the conventional manner?
3. Do I have my terms correct? I mean is it correct to say "Call the
class?"

Thanks.

Re: More On Class by Jonathan

Jonathan
Thu Dec 07 16:29:45 CST 2006


"Greg Maxey" <gmaxey@mvps.org> wrote in message
news:1165513614.334792.165000@j44g2000cwa.googlegroups.com...
> Last week Jonathan, Karl, and Jean-Guy where schooling me on Class
> modules. I have read the articles that Jonathan posted and wanted to
> try to put theory to practice.
>
> Submitted for comments by those or any other master.
>
> With the input of a few others, I have put together a routine that
> ensures the input to a VBA input box is a numeric whole number greater
> than five. It is several lines of code and I thought perhaps that it
> could be a "Class" and if I need a whole number greater than 5 several
> times in a procedure that I could call the class.
>
> Here is my testing procedure:
>
> Sub TestOfClass()
> Dim myNum As myNumClass
> Dim i As Long
> Set myNum = New myNumClass
> For i = 1 To myNum.lngNumber
> Debug.Print "Test1"
> Next i
> Set myNum = New myNumClass
> For i = 1 To myNum.lngNumber
> Debug.Print "Test2"
> Next i
> End Sub
>
> I created a Class named myNumClass and entered this code:
>
> Private mLngNumber As Long
> Private Sub Class_Initialize()
> Dim strInput As String
> Dim bInValid As Boolean
> Do
> bInValid = False
> strInput = InputBox("Enter a whole number greater than 5", _
> "Number Input", "0")
> If strInput = vbNullString Then Exit Sub
> On Error Resume Next
> If strInput <> CLng(strInput) Or CLng(strInput) <= 5 Then
> If Err.Number = 13 Then
> bInValid = True
> On Error GoTo 0
> Else
> bInValid = True
> End If
> End If
> If bInValid Then
> MsgBox "You must enter a valid whole number that is > 5."
> End If
> Loop While bInValid
> mLngNumber = strInput
> End Sub
> Property Get lngNumber() As Long
> lngNumber = mLngNumber
> End Property
>
> When I run TestofClass, I see the results that I expect. My questions
> are:
>
> 1. Is this a sensible use of a class?

For a single property, probably not, except as a means of learning how to
write a class.

For a class to be worthwhile, you would probably want one or more of the
following to be true

- two or more related properties
- properties that have some effect on each other
- some kind of internal state (e.g. the outputs are dependent on internal
variables as well as on inputs
- events raised by changes within the class

For instance, you could extend the class by having UpperBound and LowerBound
properties defining the range of numbers which the user can enter into the
inputbox.


> 2. Is it constructed in the conventional manner?

I would have a Show method which displays the InputBox and returns the
number. That way you can use the class repeatedly without having to set it
to Nothing and then re-assign it.


> 3. Do I have my terms correct? I mean is it correct to say "Call the
> class?"

You instantiate the class - create an instance of it. You call methods, and
read or write properties.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup



Re: More On Class by Greg

Greg
Thu Dec 07 17:23:23 CST 2006

Jonathan,

Thanks for your comments. It was done pretty much to learn how to write a
class. I am interested in pursuing your other suggestions with this
example. I don't really know where to beginning, but I will claw at it for
awhile and come back for help if I need it.

Thanks again.



--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Jonathan West wrote:
> "Greg Maxey" <gmaxey@mvps.org> wrote in message
> news:1165513614.334792.165000@j44g2000cwa.googlegroups.com...
>> Last week Jonathan, Karl, and Jean-Guy where schooling me on Class
>> modules. I have read the articles that Jonathan posted and wanted to
>> try to put theory to practice.
>>
>> Submitted for comments by those or any other master.
>>
>> With the input of a few others, I have put together a routine that
>> ensures the input to a VBA input box is a numeric whole number
>> greater than five. It is several lines of code and I thought
>> perhaps that it could be a "Class" and if I need a whole number
>> greater than 5 several times in a procedure that I could call the
>> class. Here is my testing procedure:
>>
>> Sub TestOfClass()
>> Dim myNum As myNumClass
>> Dim i As Long
>> Set myNum = New myNumClass
>> For i = 1 To myNum.lngNumber
>> Debug.Print "Test1"
>> Next i
>> Set myNum = New myNumClass
>> For i = 1 To myNum.lngNumber
>> Debug.Print "Test2"
>> Next i
>> End Sub
>>
>> I created a Class named myNumClass and entered this code:
>>
>> Private mLngNumber As Long
>> Private Sub Class_Initialize()
>> Dim strInput As String
>> Dim bInValid As Boolean
>> Do
>> bInValid = False
>> strInput = InputBox("Enter a whole number greater than 5", _
>> "Number Input", "0")
>> If strInput = vbNullString Then Exit Sub
>> On Error Resume Next
>> If strInput <> CLng(strInput) Or CLng(strInput) <= 5 Then
>> If Err.Number = 13 Then
>> bInValid = True
>> On Error GoTo 0
>> Else
>> bInValid = True
>> End If
>> End If
>> If bInValid Then
>> MsgBox "You must enter a valid whole number that is > 5."
>> End If
>> Loop While bInValid
>> mLngNumber = strInput
>> End Sub
>> Property Get lngNumber() As Long
>> lngNumber = mLngNumber
>> End Property
>>
>> When I run TestofClass, I see the results that I expect. My
>> questions are:
>>
>> 1. Is this a sensible use of a class?
>
> For a single property, probably not, except as a means of learning
> how to write a class.
>
> For a class to be worthwhile, you would probably want one or more of
> the following to be true
>
> - two or more related properties
> - properties that have some effect on each other
> - some kind of internal state (e.g. the outputs are dependent on
> internal variables as well as on inputs
> - events raised by changes within the class
>
> For instance, you could extend the class by having UpperBound and
> LowerBound properties defining the range of numbers which the user
> can enter into the inputbox.
>
>
>> 2. Is it constructed in the conventional manner?
>
> I would have a Show method which displays the InputBox and returns the
> number. That way you can use the class repeatedly without having to
> set it to Nothing and then re-assign it.
>
>
>> 3. Do I have my terms correct? I mean is it correct to say "Call
>> the class?"
>
> You instantiate the class - create an instance of it. You call
> methods, and read or write properties.



Re: More On Class by Greg

Greg
Thu Dec 07 19:31:40 CST 2006

Jonathan,

Sometimes I just hate this stuff gggrrrr.

After struggling for nearly two hours, I simply can't get the grasp of
Propert Set.

I wanted to try to incorporate a LBound and UBound property of the class. I
had no trouble using LET and GET statements, but keep get a compile error
any time I try to use the SET statement.

I created a new class modules "clsUnderstandingSet" with this code:

Option Explicit
Private mUBound As Long
Private mLBound As Long
Private mModuleObject As Object
Property Get lngUBound() As Long
lngUBound = mUBound
End Property
Property Let lngUBound(pVal As Long)
mUBound = pVal
End Property
Property Get lngLBound() As Long
lngLBound = mLBound
End Property
'Property Set lngLBound(pVal As Long)
' Set mLBound = pVal
'End Property
Private Sub Class_Initialize()
Dim pVal As Long
Dim pObject As Object
pVal = 6
'Set Me.lngLBound = pVal
Set Me.MyObject = New Word.Application
Set pObject = Me.MyObject
End Sub
Public Property Get MyObject() As Object
Set MyObject = mModuleObject
End Property
Public Property Set MyObject(NewValue As Object)
Set mModuleObject = NewValue
End Property

and a calling macro with this code:

Sub TestClass()
Dim myTest As clsUnderstandingSet
Set myTest = New clsUnderstandingSet
myTest.lngUBound = 10
MsgBox myTest.lngLBound & " and " & myTest.lngUBound
End Sub

The stetted out statements in the Class module are what is giving me fits.
You can run the code as is and see that the UBound property is "LET" to 10,
and I copied a working SET statement from Google to set the MyOject
variable, but I can't get SET to work to set the LBound variable.

What am I doing wrong??






--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Jonathan West wrote:
> "Greg Maxey" <gmaxey@mvps.org> wrote in message
> news:1165513614.334792.165000@j44g2000cwa.googlegroups.com...
>> Last week Jonathan, Karl, and Jean-Guy where schooling me on Class
>> modules. I have read the articles that Jonathan posted and wanted to
>> try to put theory to practice.
>>
>> Submitted for comments by those or any other master.
>>
>> With the input of a few others, I have put together a routine that
>> ensures the input to a VBA input box is a numeric whole number
>> greater than five. It is several lines of code and I thought
>> perhaps that it could be a "Class" and if I need a whole number
>> greater than 5 several times in a procedure that I could call the
>> class. Here is my testing procedure:
>>
>> Sub TestOfClass()
>> Dim myNum As myNumClass
>> Dim i As Long
>> Set myNum = New myNumClass
>> For i = 1 To myNum.lngNumber
>> Debug.Print "Test1"
>> Next i
>> Set myNum = New myNumClass
>> For i = 1 To myNum.lngNumber
>> Debug.Print "Test2"
>> Next i
>> End Sub
>>
>> I created a Class named myNumClass and entered this code:
>>
>> Private mLngNumber As Long
>> Private Sub Class_Initialize()
>> Dim strInput As String
>> Dim bInValid As Boolean
>> Do
>> bInValid = False
>> strInput = InputBox("Enter a whole number greater than 5", _
>> "Number Input", "0")
>> If strInput = vbNullString Then Exit Sub
>> On Error Resume Next
>> If strInput <> CLng(strInput) Or CLng(strInput) <= 5 Then
>> If Err.Number = 13 Then
>> bInValid = True
>> On Error GoTo 0
>> Else
>> bInValid = True
>> End If
>> End If
>> If bInValid Then
>> MsgBox "You must enter a valid whole number that is > 5."
>> End If
>> Loop While bInValid
>> mLngNumber = strInput
>> End Sub
>> Property Get lngNumber() As Long
>> lngNumber = mLngNumber
>> End Property
>>
>> When I run TestofClass, I see the results that I expect. My
>> questions are:
>>
>> 1. Is this a sensible use of a class?
>
> For a single property, probably not, except as a means of learning
> how to write a class.
>
> For a class to be worthwhile, you would probably want one or more of
> the following to be true
>
> - two or more related properties
> - properties that have some effect on each other
> - some kind of internal state (e.g. the outputs are dependent on
> internal variables as well as on inputs
> - events raised by changes within the class
>
> For instance, you could extend the class by having UpperBound and
> LowerBound properties defining the range of numbers which the user
> can enter into the inputbox.
>
>
>> 2. Is it constructed in the conventional manner?
>
> I would have a Show method which displays the InputBox and returns the
> number. That way you can use the class repeatedly without having to
> set it to Nothing and then re-assign it.
>
>
>> 3. Do I have my terms correct? I mean is it correct to say "Call
>> the class?"
>
> You instantiate the class - create an instance of it. You call
> methods, and read or write properties.



Re: More On Class by Jonathan

Jonathan
Thu Dec 07 20:03:18 CST 2006


"Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
news:uQUTZimGHHA.3540@TK2MSFTNGP02.phx.gbl...
> Jonathan,
>
> Sometimes I just hate this stuff gggrrrr.
>
> After struggling for nearly two hours, I simply can't get the grasp of
> Propert Set.
>
> I wanted to try to incorporate a LBound and UBound property of the class.
> I had no trouble using LET and GET statements, but keep get a compile
> error any time I try to use the SET statement.

You only use Property Set if your property is an object rather then a value.
Otherwise you just use Property Let.

You would only ever have both Property Let and Property Set for the same
property if you want the ability to assign both an object and its default
property to the same property name. Forget about this - the number of times
you would need this is vanishingly small.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup



Re: More On Class by Greg

Greg
Thu Dec 07 21:42:31 CST 2006

Jonathan,

This is still a bit fussy. But if I understand, then I could set the
variable values in the Class initialize procedure like this:

Option Explicit
Private mUBound As Long
Private mLBound As Long

Property Get lngUBound() As Long
lngUBound = mUBound
End Property

Property Let lngUBound(pVal As Long)
mUBound = pVal
End Property

Property Get lngLBound() As Long
lngLBound = mLBound
End Property

Property Let lngLBound(pVal As Long)
mLBound = pVal
End Property

Private Sub Class_Initialize()
Dim pObject As Object
Me.lngLBound = 5
Me.lngUBound = 10
End Sub

I guess that part I remain puzzled about is: How do you create a variable
that has a value say "5" that is then read only? I mean that couldn't be
changed to 10 or 15, or 100 or whatever with a statement like:

Sub TestClass()
Dim myTest As clsUnderstandingSet
Set myTest = New clsUnderstandingSet
MsgBox myTest.lngLBound & " and " & myTest.lngUBound
myTest.lngLBound = 100
End Sub

Thanks



Me.lngLBount = 10





--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Jonathan West wrote:
> "Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
> news:uQUTZimGHHA.3540@TK2MSFTNGP02.phx.gbl...
>> Jonathan,
>>
>> Sometimes I just hate this stuff gggrrrr.
>>
>> After struggling for nearly two hours, I simply can't get the grasp
>> of Propert Set.
>>
>> I wanted to try to incorporate a LBound and UBound property of the
>> class. I had no trouble using LET and GET statements, but keep get a
>> compile error any time I try to use the SET statement.
>
> You only use Property Set if your property is an object rather then a
> value. Otherwise you just use Property Let.
>
> You would only ever have both Property Let and Property Set for the
> same property if you want the ability to assign both an object and
> its default property to the same property name. Forget about this -
> the number of times you would need this is vanishingly small.



Re: More On Class by Jonathan

Jonathan
Fri Dec 08 03:03:44 CST 2006


"Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
news:OnR3grnGHHA.4116@TK2MSFTNGP05.phx.gbl...
> Jonathan,
>
> This is still a bit fussy. But if I understand, then I could set the
> variable values in the Class initialize procedure like this:
>
> Option Explicit
> Private mUBound As Long
> Private mLBound As Long
>
> Property Get lngUBound() As Long
> lngUBound = mUBound
> End Property
>
> Property Let lngUBound(pVal As Long)
> mUBound = pVal
> End Property
>
> Property Get lngLBound() As Long
> lngLBound = mLBound
> End Property
>
> Property Let lngLBound(pVal As Long)
> mLBound = pVal
> End Property
>
> Private Sub Class_Initialize()
> Dim pObject As Object
> Me.lngLBound = 5
> Me.lngUBound = 10
> End Sub
>
> I guess that part I remain puzzled about is: How do you create a variable
> that has a value say "5" that is then read only? I mean that couldn't be
> changed to 10 or 15, or 100 or whatever with a statement like:
>
> Sub TestClass()
> Dim myTest As clsUnderstandingSet
> Set myTest = New clsUnderstandingSet
> MsgBox myTest.lngLBound & " and " & myTest.lngUBound
> myTest.lngLBound = 100
> End Sub
>

Within the class you can change mUBound and mLBound directly, from any
routine within the class, Therefore you could do the following

Private Sub Class_Initialize()
Dim pObject As Object
mLBound = 5
mUBound = 10
End Sub

This then gets reflected in the values returned by the properties. The
properties can then be read-only if you wish.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup





Re: More On Class by Greg

Greg
Fri Dec 08 05:15:18 CST 2006

Jonathan,

> Within the class you can change mUBound and mLBound directly, from any
> routine within the class, Therefore you could do the following
>
> Private Sub Class_Initialize()
> Dim pObject As Object
> mLBound = 5
> mUBound = 10
> End Sub

There lies my question. Let's say I wish to make the variable values "read
only" after I have established them as indicated above.

How do I do that? Here an now I can run initialization code as you show and
still the following will "write" a new value to the variable:

Sub TestClass()
Dim myTest As clsUnderstandingSet
Set myTest = New clsUnderstandingSet
MsgBox myTest.lngLBound & " and " & myTest.lngUBound
myTest.lngLBound = 100
MsgBox myTest.lngLBound 'This returns 100
End Sub

If the variable were read only I would expect some kind of error.


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Jonathan West wrote:
> "Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
> news:OnR3grnGHHA.4116@TK2MSFTNGP05.phx.gbl...
>> Jonathan,
>>
>> This is still a bit fussy. But if I understand, then I could set the
>> variable values in the Class initialize procedure like this:
>>
>> Option Explicit
>> Private mUBound As Long
>> Private mLBound As Long
>>
>> Property Get lngUBound() As Long
>> lngUBound = mUBound
>> End Property
>>
>> Property Let lngUBound(pVal As Long)
>> mUBound = pVal
>> End Property
>>
>> Property Get lngLBound() As Long
>> lngLBound = mLBound
>> End Property
>>
>> Property Let lngLBound(pVal As Long)
>> mLBound = pVal
>> End Property
>>
>> Private Sub Class_Initialize()
>> Dim pObject As Object
>> Me.lngLBound = 5
>> Me.lngUBound = 10
>> End Sub
>>
>> I guess that part I remain puzzled about is: How do you create a
>> variable that has a value say "5" that is then read only? I mean
>> that couldn't be changed to 10 or 15, or 100 or whatever with a
>> statement like: Sub TestClass()
>> Dim myTest As clsUnderstandingSet
>> Set myTest = New clsUnderstandingSet
>> MsgBox myTest.lngLBound & " and " & myTest.lngUBound
>> myTest.lngLBound = 100
>> End Sub
>>
>
> Within the class you can change mUBound and mLBound directly, from any
> routine within the class, Therefore you could do the following
>
> Private Sub Class_Initialize()
> Dim pObject As Object
> mLBound = 5
> mUBound = 10
> End Sub
>
> This then gets reflected in the values returned by the properties. The
> properties can then be read-only if you wish.



Re: More On Class by Jean-Guy

Jean-Guy
Fri Dec 08 06:49:49 CST 2006

Greg Maxey was telling us:
Greg Maxey nous racontait que :

> Jonathan,
>
>> Within the class you can change mUBound and mLBound directly, from
>> any routine within the class, Therefore you could do the following
>>
>> Private Sub Class_Initialize()
>> Dim pObject As Object
>> mLBound = 5
>> mUBound = 10
>> End Sub
>
> There lies my question. Let's say I wish to make the variable values
> "read only" after I have established them as indicated above.
>
> How do I do that? Here an now I can run initialization code as you
> show and still the following will "write" a new value to the variable:
>
> Sub TestClass()
> Dim myTest As clsUnderstandingSet
> Set myTest = New clsUnderstandingSet
> MsgBox myTest.lngLBound & " and " & myTest.lngUBound
> myTest.lngLBound = 100
> MsgBox myTest.lngLBound 'This returns 100
> End Sub
>
> If the variable were read only I would expect some kind of error.
>

The Let statements in the Class modules are the one that make your
properties both "writable". To make them read only, use only the Get
Statements:
(That is to say that Let allow the property to be written, and Get allows it
to be read).

Option Explicit

Property Get lngUBound() As Long
lngUBound = 10
End Property

Property Get lngLBound() As Long
lngLBound = 5
End Property

Then, if you try to run your TestClass Sub, you will get an error at compile
time.

Hre is a nice page to read up on the topic:
http://www.cpearson.com/excel/ClassModules.htm

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org



Re: More On Class by Jonathan

Jonathan
Fri Dec 08 06:49:40 CST 2006


"Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
news:ee0DhorGHHA.4688@TK2MSFTNGP04.phx.gbl...
> Jonathan,
>
>> Within the class you can change mUBound and mLBound directly, from any
>> routine within the class, Therefore you could do the following
>>
>> Private Sub Class_Initialize()
>> Dim pObject As Object
>> mLBound = 5
>> mUBound = 10
>> End Sub
>
> There lies my question. Let's say I wish to make the variable values
> "read only" after I have established them as indicated above.

Read-only properties are ones that don't have a Property Let or Property Set
routine - they only have a Property Get routine.

That way, you can set the underlying variables within other routines inside
the class module, but not give the calling routine the opportunity to change
the property values directly.

Always distinguish between what you can do using code within the class (i.e.
just about anything), and what interfaces you choose to define to the
outside (which can be limited in whatever way you want).


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup



Re: More On Class by Greg

Greg
Fri Dec 08 06:57:50 CST 2006

"Plink" and the brigth light floods in removing the fog of confussion.
I misread your reply Jonathan. I see now that you meant that the
module level variables could be set directly and I that I don't use a
LET statement.

Thanks.

Jonathan West wrote:
> "Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
> news:OnR3grnGHHA.4116@TK2MSFTNGP05.phx.gbl...
> > Jonathan,
> >
> > This is still a bit fussy. But if I understand, then I could set the
> > variable values in the Class initialize procedure like this:
> >
> > Option Explicit
> > Private mUBound As Long
> > Private mLBound As Long
> >
> > Property Get lngUBound() As Long
> > lngUBound = mUBound
> > End Property
> >
> > Property Let lngUBound(pVal As Long)
> > mUBound = pVal
> > End Property
> >
> > Property Get lngLBound() As Long
> > lngLBound = mLBound
> > End Property
> >
> > Property Let lngLBound(pVal As Long)
> > mLBound = pVal
> > End Property
> >
> > Private Sub Class_Initialize()
> > Dim pObject As Object
> > Me.lngLBound = 5
> > Me.lngUBound = 10
> > End Sub
> >
> > I guess that part I remain puzzled about is: How do you create a variable
> > that has a value say "5" that is then read only? I mean that couldn't be
> > changed to 10 or 15, or 100 or whatever with a statement like:
> >
> > Sub TestClass()
> > Dim myTest As clsUnderstandingSet
> > Set myTest = New clsUnderstandingSet
> > MsgBox myTest.lngLBound & " and " & myTest.lngUBound
> > myTest.lngLBound = 100
> > End Sub
> >
>
> Within the class you can change mUBound and mLBound directly, from any
> routine within the class, Therefore you could do the following
>
> Private Sub Class_Initialize()
> Dim pObject As Object
> mLBound = 5
> mUBound = 10
> End Sub
>
> This then gets reflected in the values returned by the properties. The
> properties can then be read-only if you wish.
>
>
> --
> Regards
> Jonathan West - Word MVP
> www.intelligentdocuments.co.uk
> Please reply to the newsgroup


Re: More On Class by Greg

Greg
Fri Dec 08 07:01:02 CST 2006

JGM,

The light bulb flashed just moments ago and I understand the process
now. Thanks for your post and I am off to read your article shortly.


Jean-Guy Marcil wrote:
> Greg Maxey was telling us:
> Greg Maxey nous racontait que :
>
> > Jonathan,
> >
> >> Within the class you can change mUBound and mLBound directly, from
> >> any routine within the class, Therefore you could do the following
> >>
> >> Private Sub Class_Initialize()
> >> Dim pObject As Object
> >> mLBound = 5
> >> mUBound = 10
> >> End Sub
> >
> > There lies my question. Let's say I wish to make the variable values
> > "read only" after I have established them as indicated above.
> >
> > How do I do that? Here an now I can run initialization code as you
> > show and still the following will "write" a new value to the variable:
> >
> > Sub TestClass()
> > Dim myTest As clsUnderstandingSet
> > Set myTest = New clsUnderstandingSet
> > MsgBox myTest.lngLBound & " and " & myTest.lngUBound
> > myTest.lngLBound = 100
> > MsgBox myTest.lngLBound 'This returns 100
> > End Sub
> >
> > If the variable were read only I would expect some kind of error.
> >
>
> The Let statements in the Class modules are the one that make your
> properties both "writable". To make them read only, use only the Get
> Statements:
> (That is to say that Let allow the property to be written, and Get allows it
> to be read).
>
> Option Explicit
>
> Property Get lngUBound() As Long
> lngUBound = 10
> End Property
>
> Property Get lngLBound() As Long
> lngLBound = 5
> End Property
>
> Then, if you try to run your TestClass Sub, you will get an error at compile
> time.
>
> Hre is a nice page to read up on the topic:
> http://www.cpearson.com/excel/ClassModules.htm
>
> --
>
> Salut!
> _______________________________________
> Jean-Guy Marcil - Word MVP
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org


Re: More On Class by Jonathan

Jonathan
Sat Dec 09 11:23:08 CST 2006


"Greg Maxey" <gmaxey@mvps.org> wrote in message
news:1165582669.974561.297550@j44g2000cwa.googlegroups.com...
> "Plink" and the brigth light floods in removing the fog of confussion.
> I misread your reply Jonathan. I see now that you meant that the
> module level variables could be set directly and I that I don't use a
> LET statement.

Exactly so!


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup



Re: More On Class by Greg

Greg
Sat Dec 09 11:34:28 CST 2006

Jonathan,

While your article links are informative, they are more easily understood
after reading the one by Chip Pearson that Jean-Guy provided the link to in
his post above. You might considers adding that one to your list of
tuitorials for instructing beginners like me.

Thanks again. I may be back on this topic or a new one as I continue to
attempt to build on my InputBox class. I realize it may never have much
functional merit but it allows me to practice and develop skills.



--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Jonathan West wrote:
> "Greg Maxey" <gmaxey@mvps.org> wrote in message
> news:1165582669.974561.297550@j44g2000cwa.googlegroups.com...
>> "Plink" and the brigth light floods in removing the fog of
>> confussion. I misread your reply Jonathan. I see now that you meant
>> that the module level variables could be set directly and I that I
>> don't use a LET statement.
>
> Exactly so!



Re: More On Class by Jonathan

Jonathan
Sat Dec 09 12:07:49 CST 2006


"Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
news:O3gPIh7GHHA.1064@TK2MSFTNGP04.phx.gbl...
> Jonathan,
>
> While your article links are informative, they are more easily understood
> after reading the one by Chip Pearson that Jean-Guy provided the link to
> in his post above. You might considers adding that one to your list of
> tuitorials for instructing beginners like me.

I agree. I was unaware of it when I gave you the other links.

> Thanks again. I may be back on this topic or a new one as I continue to
> attempt to build on my InputBox class. I realize it may never have much
> functional merit but it allows me to practice and develop skills.

Having the chance to develop skills at leaisure on a project that doesn't
matter too much is a very good idea.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup