[AccessD] Scope Testing

John Colby jwcolby at gmail.com
Sun Jan 16 10:14:22 CST 2022


I created two modules as shown below.  One I named basTestingFromHere and
the other basToBeTested.  Private objects in basToBeTested would not even
compile when referenced from basTestingFromHere - which is why those things
are commented out.  I created variables in the header as well as
functions.  You can see for yourself how these things work.

Classes are more or less the same, except as Stuart mentioned,
1) the class has to be instantiated
2) The instance itself has t be referenced as the first part and then
.SomeInteriorThingie

MyInstantiatedObject.MyPublicFunction()

As we know, a class can be instantiated multiple times and the functions
and data inside of each instance are distinct to that specific instance.

dim clsPerson as cJohnC
dim clsPerso as cArthurF

debug.print cJohnC.fFirstName()
debug.print cArthurF.fFirstName()

BTW for those not familiar with classes, the physical code inside the class
is only ever stored once, ie it is loaded into memory when the class is
instantiated the first time,  The DATA inside the class is unique to each
instance.

The following is the code modules I created.  Enjoy playing with them.  If
anyone wants the same thing for classes I will do that.  I didn't simply
because there is a large "I don't use classes because they can't be
inherited " thing going on in AccessD and so why spend my time if no one
will look at it anyway.

'
'BasToBeTested
'
Option Compare Database
Option Explicit

Dim StrScope As String
Private strPrivateScope As String
Public strPublicScope As String

Function SetUp()
    StrScope = "Unknown scope, only dimmmed"
    strPrivateScope = "dimmed Private Scope"
    strPublicScope = "dimmed public scope"
End Function


Private Function fPrivateScope()
    fPrivateScope = "Private function"
End Function

Public Function fPublicScope()
    fPublicScope = "Public scope"
End Function

Function fUnknownScope()
    fUnknownScope = "Unknown Scope"
End Function

'
'basTestingFromHere
'
Option Compare Database
Option Explicit

Function fTestItAll()
    'Debug.Print StrScope
    'Debug.Print strPrivateScope
    Debug.Print strPublicScope

    'Debug.Print fPrivateScope()
    Debug.Print fPublicScope()
    Debug.Print fUnknownScope()

    Debug.Print basToBeTested.fPublicScope()
    Debug.Print basToBeTested.fUnknownScope()
    Debug.Print basToBeTested.SetUp()
    Debug.Print basToBeTested.strPublicScope
End Function

-- 
John W. Colby
Colby Consulting


More information about the AccessD mailing list