Creating Classes & ActiveX Controls

Specifying when properties can be set and read

If you want a property to be read-only at design time, then you can check the Ambient.UserMode property. It returns False when at design time, and True when at run-time.

Dim m_vFile As Variant
Public Property Get vFile() As Variant
    '// we are happy for the client to read vFile at both run time and design time
    vFile = m_vFile
End Property

Public Property Let vFile(ByVal New_vFile As Variant)
    '// only allowed to set value at run time
    '// raise an error if we try to set it at design time.
    If Ambient.UserMode = False Then Err.Raise 382
    m_vFile = New_vFile
    PropertyChanged "vFile"
End Property

So, you can see that if you only want to be able to read and set a property at design time, then you insert
If Ambient.UserMode = False Then Err.Raise 387
into both the Property Let and Property Get procedures, and likewise, if you only want to be able to read and set a property at run time, then you insert
If Ambient.UserMode Then Err.Raise 387
into both the Property Let and Property Get procedures.

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Engineers are all basically high-functioning autistics who have no idea how normal people do stuff.” - Cory Doctorow