View Single Post
Old 12-09-2017, 05:48 AM   #11
Newly Registered User
jleach's Avatar
Join Date: Jan 2012
Location: New York, NY
Posts: 308
Thanks: 16
Thanked 70 Times in 70 Posts
jleach will become famous soon enough
Re: Declaring adn defininf public variables

Originally Posted by The_Doc_Man View Post
"Public" in a class module is close to totally meaningless.
Curious why you say that. Public and private methods and properties have as much use in class modules as they do anywhere else:

'Book class
Option Explicit

Private mPageCount As Integer
Private mCurrentPage As Integer

'readonly with internal validation
Public Property Get CurrentPage() As Integer
  CurrentPage = mCurrentPage
End Property
Private Property Set CurrentPage(i As Integer)
  If i < 1 OR > Me.PageCount Then Err.Raise 9 'out of range
  mCurrentPage = i
End Property

Public Property Get PageCount() As Integer
  PageCount = mPageCount
End Property
Private Property Set PageCount(i as Integer)
  mPageCount = CalculatePageCount()
End Property

Public Sub GotoPage(PageNumber As Integer) 
  Me.CurrentPage = PageNumber
  ... other stuff
End Sub
A little rough around the edges but serves well enough for an example. I'm not sure I've ever written a module where I didn't want most of the implementation hidden in private procedures and have only the interface exposed through public ones.

- Jack D. Leach

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Microsoft MVP 2012-2016
jleach is offline   Reply With Quote