how to call a member variable in a class

how to call a member variable in a class

Anonymous
Not applicable
286 Views
4 Replies
Message 1 of 5

how to call a member variable in a class

Anonymous
Not applicable
given a class clsWeldSym
with a member var
Private mWeldInsPt As Variant

Property Let inspt(val As Variant)
mWeldInsPt = val
End Property
Property Get inspt() As Variant
inspt = mWeldInsPt
End Property

and a Draw method

Public Sub Draw()


I'm probably going about this in the wrong way, but here's what I'm trying
in the calling sub:

dim ws as clsWeldSym
Set ws = New clsWeldSym

after setting anumber of variables the calling sub goes

ws.draw


in the clsWeldSym class module the draw method starts out...
Public Sub Draw()

'check for existence of weld sym

'here I want to get a point, and set to the member variable mWeldSymInsPt
using the InsPt property of the clsWeldSym object

ws.inspt = doc.Utility.GetPoint(, "Pick point for weld sym")
but the ws was declared in the calling function, not in the class mod
itself, so I guess I should be getting the point outside of the method eh,
before calling ws.draw?
then in ws.draw for the insertion point would I just use the member variable
itself, or call the get property?

inside a method in a class, how do I refer to class properties? or do I just
use the member variables themselves directly.
0 Likes
287 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
>
> inside a method in a class, ... do I just
> use the member variables themselves directly. [?]
>

Yes... if you and I are thinking of "member variables" as the same thing.
For example, in CommonDialog.cls from www.acadx.com...

Private mvarInitDir As String 'member variable dimensioned at the module
level

Public Property Let InitDir(newVal As String)
mvarInitDir = newVal 'assign member variable
end property

Public Function ShowOpen() As Long
Dim ofn As OPENFILENAME
ofn.lpstrInitialDir = mvarInitDir 'use member variable in a method
routine
end property

I think there should be a mVar for every Property Let sub.
Use the Let subroutines to check and discard invalid inputs, so that when
you use the mVar in your methods you never have to check it for being the
source of errors.
(Ex: Person.IQ = -120 ... mVar would be set to minimum of 1)


James
0 Likes
Message 3 of 5

Anonymous
Not applicable
Thanks James,
Yes, that's exactly what I meant by "member variable".
So if the class itself (a sub in the class) needs to use or change a 'mVar'
it can deal with it directly, without 'breaking the law of encapsulation'
but because it's encapsulated in the class, if an 'outside' sub wants to get
or set it they have to use the class properties to do so, right?
I think I get it!?!

Thanks again,
Mark

"James Belshan" wrote in message
news:66997E8FB41B8DFA02A9EF17D3E03E9A@in.WebX.maYIadrTaRb...
> >
> > inside a method in a class, ... do I just
> > use the member variables themselves directly. [?]
> >
>
> Yes... if you and I are thinking of "member variables" as the same thing.
0 Likes
Message 4 of 5

Anonymous
Not applicable
Mark Propst wrote:
> Thanks James,
> Yes, that's exactly what I meant by "member variable".
> So if the class itself (a sub in the class) needs to use or change a
> 'mVar' it can deal with it directly, without 'breaking the law of
> encapsulation' but because it's encapsulated in the class, if an
> 'outside' sub wants to get or set it they have to use the class
> properties to do so, right?
> I think I get it!?!

Yep, you got it.

--
"It's more important that you know how to find the answer than to have
the answer." - Me
0 Likes
Message 5 of 5

Anonymous
Not applicable
Thanks Frank,
You guys are fantastic teachers.
Thank you again and again,
Mark

"Frank Oquendo" wrote in message
news:0AC7D612F97DF2B0344871C800BBB39D@in.WebX.maYIadrTaRb...

>
> Yep, you got it.
>
> --
> "It's more important that you know how to find the answer than to have
> the answer." - Me
>
>
0 Likes