Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I? : Hide nested classes

Status
Not open for further replies.

thefarg

Programmer
Jan 25, 2012
94
NZ
Hi. I have a class consisting of several nested classes. How do I make these hidden to the project while still allowing them to be accessed through the parent classes namespace? If It was just the functions, properties etc, I could make them private. Can I make private or friend classes? Any way I can accomplish this?

Cheers
Mike
 
FYI. If this is a procedure that does not return a value
ChangeGraph (BorusDB.Settings.HomeGraphNumber)
It will compile, but errors at runtime.

It is hard to see the problem without seeing the setter/getter and/or initialization of both
Parent Class (BorusDB's) and cBDSettings.

The place I usually make a mistake especially that I go back and forth between .net and vba is in the setter. If it is an object it is a Set not a Let, and needs to have "Set" in the assignment. I often forget one.

Public Property Set settings(byval Value as CBdSettings)
'I forget the set below.
msettings = Value
'set mSettings = value
end property

Same with the Get.
 
One more thing. You asked about how you should initialise. The setters and getters should make no difference. However there are a couple of variations.

assume i do have private class variables
Code:
private mSettings as cBDSettings
private mShortCuts as cBDShortCuts
private mCompanyData as CBDBprops
what you show is fine
Code:
Private Sub Class_Initialize()
  Set mSettings = New cBDBSettings
  Set mShortcuts = New cBDBShortcuts
  Set mCompanyData = New cBDBProps
End Sub

If you have setters and getters you could modify it to
Code:
Private Sub Class_Initialize()
  Set me.Settings = New cBDBSettings
  Set me.Shortcuts = New cBDBShortcuts
  Set me.CompanyData = New cBDBProps
End Sub
I like to use setters and getters inside my class for several reasons and one is simply intellisense. If I type me.c then companydata comes up. Another is that I make the setter and getter names long and easily interpretable. I may make the class variables shorter or more discernable. The two methods accomplish the same thing.

Another method is simply
Code:
private mSettings as new cBDSettings
private mShortCuts as new cBDShortCuts
private mCompanyData as new CBDBprops
with no code in the initialize event. I think in this method the memory locations for the contained objects is reserved when the parent is declared vs instantiated. I may be wrong on that.
 
I like to use setters and getters inside my class for several reasons and one is simply intellisense
.
Me too. However, I have this with the existing code.
If this is a procedure that does not return a value
ChangeGraph (BorusDB.Settings.HomeGraphNumber)
It will compile, but errors at runtime.
Its actually a sub, so no return value. Using my original code, it compliles and doesnt error at runtime.
 
If this works
BorusDB.Settings.HomeGraphNumber
when HomeGraphNumber is a public variable, but fails when it is returned by an accessor. That tells me that your get has an problem and the your are setting the value correctly.
 
Comes up with an error both getting and setting. Say I msgbox (or debug.print, watcher etc)
BorusDB.Settings.HomeGraphNumber .... Error, as above
BorusDB.Settings .... empty string, no error. Has no default so not expecting anything. Seems only to error on access to the sub-composite classes. All properties in these classes use let (only accessing registry, not objects). Seems that its wanting an object when the sub composite returbs a string or int. I have seen an example similar to yours so I'm not sure why it wont work for me.
 
Can you show the setter and getter for homegraphnumber. Are you able to verify that you can set and get "Settings"?
 
OK. LET and get for HomeGraphNumber.

Code:
[COLOR=green]'Which Graph No# to show on main form[/color]
Property Get HomeGraphNumber() As Integer
    HomeGraphNumber = ReadRegValue("HKCU\Software\Bugs or Us\Bugs or Us Business System\Version 1.0.0\Settings\HomeGraphNumber")
End Property

Property Let HomeGraphNumber(ByVal GraphNumber As Integer)
[COLOR=green]    'Change Home Graph using slider and saving settings
    ' When changed the subform leaves its position
    ' So we pop it back using coordinates [/color]
    Dim SubformTop As Integer
    Dim SubformLeft As Integer
        With Forms.frmHome
                With sbfSalesPivot
                    SubformLeft = .Left
                    SubformTop = .Top

                    .Form.Visible = False
                    .SourceObject = ("frmHome_SalesAnalysisSubform" & GraphNumber)
                    .Top = SubformTop
                    .Left = SubformLeft
                    .Form.Visible = True
                End With
            .sldGraph.Tag = GraphNumber
            .sldGraph = GraphNumber
        End With
    CreateRegKey "HKCU\Software\Bugs or Us\Bugs or Us Business System\Version 1.0.0\Settings\HomeGraphNumber", GraphNumber, "REG_DWORD"
End Property

I have 5 subforms, named frmHome_SalesAnalysisSubform1 through 5. .sldGraph is a Slider control. Logic for registry reads and writes is contained in associated procedures.
I can't verify that im able to get or set as It doesnt appear to work using any of the code we have looked at. So far, only publicly declared instance of the sub-composite classes works.
 
Unrelated, but one thing you may want to consider. You can save persistent database information to the properties collection by creating a custom property. When you save custom properties they are saved in a system table. When the database loads you can read these properties out of the DAO.database.properties collection. Little easier then using the registry.
 
Sounds like a good idea. I use it for storing Company data like Address, phone, etc. Thats in cBDBProps. I like to keep this dat with the database no matter what.
cBDBSettings is pretty much all registry. I need to access the registry to turn off Simple MAPI security popup and also to allow Word docs to be viewed in IE (webcontrol actually). Currently I use the Wscript.shell object for this as its simpler than winAPI. However it automaticallt converts to either int or string, giving me an overflow error with several settings. On my to-do list is to convert back to using winapi.
cBDBShortcuts is just to enable/disable shortcuts to desktop, start menu and quicklaunch.
So what you are saying is that the property data is saved to a system table, so is it possible to add more columns rather than just the simple Key=Value way?
 
Ah well. At the start of the project I weighed up storage of the various data between registry, table, properties or a file. I usually use registry for settings type storage but I decided to use the DB properties to store company name, phone etc type data as I like to keep that with the database, whereas the userdata can be recreated if the computer is reinstalled etc. Not sure how many users it will have but I prefer not to have those settings as simple KEY=Value otherwise it will be like User1Setting1=<value>, User1Setting2=<value>, User2Setting1=<value>, etc. Ok for only a few values but not so efficient for lots of values. Just like interfacing with an .ini . Tables have better ways of accessing the data, but registry is a pretty standardised way of dealing with user settings.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top