+ Reply to Thread
Results 1 to 3 of 3

Initialising variables values in a class module

  1. #1
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Initialising variables values in a class module

    I'm using class modules for the first time and (pretty much) getting the hang of it, but one thing I can't work out, that not even PED helps me on, is how I set an initial value for any variables declared in a class module.

    Without going into too much detail I have an integer property of the object that I'm creating that I would like to make read/write, but I want it to have a non-zero default value. To set it to this initial value do I have to trap the event of a new instance of the object being created and set default values then, or am I missing something stupidly obvious.

    Thanks in advance, and merry generic-non-religious-by-festive-time-period to everybody
    Last edited by Andrew-R; 12-24-2011 at 12:53 PM.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Initialising variables values in a class module

    Classes have an Initialize event, you can set the values in there.

    Private Sub Class_Initialize()

    End Sub

  3. #3
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Initialising variables values in a class module

    Nice and easy, thanks Bob.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1