Selasa, 11 Februari 2014

RE: [MS_AccessPros] Holding Global Variables in a Class Module

 

Not sure I go with that approach, but this is a very simple example of such a class

 

Option Explicit

 

Const mcAppName As String = "MyApp"

Const mcAppDesc As String = "An app to do something"

Const mcVersion As String = "1.01.010"

Const mcBuildDate As Date = #1/1/2014#

 

 

Public Property Get Name() As String

    Name = mcAppName

End Property

 

Public Property Get Description() As String

    Description = mcAppDesc

End Property

   

Public Property Get Version() As String

    Version = mcVersion

End Property

 

Public Property Get BuildDate() As Date

    BuildDate = mcBuildDate

End Property

 

Public Property Get AppAge() As Long

    AppAge = Date - mcBuildDate

End Property

 

And it could be used like so

 

Public Sub TestApp()

Dim myApp As App

 

    Set myApp = New App ' the class is loaded into memory and the constants setup

   

    With myApp

   

        Debug.Print .Name

        Debug.Print .Description

        Debug.Print .Version

        Debug.Print .BuildDate

        Debug.Print .Name & " (" & .Description & _

                    ") was built on " & Format(.BuildDate, "dd mmm yyyy") & _

                    ", and is therefore " & .AppAge & " days old"

    End With

End Sub

 

From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com] On Behalf Of zctek@aol.com
Sent: 11 February 2014 17:03
To: ms_access_professionals@yahoogroups.com
Subject: [MS_AccessPros] Holding Global Variables in a Class Module

 

 

Hi All,

 

Many months ago there was a discussion re. holding Global Variables in a Class Module being preferable to holding them in a standard Module because in the event of an error, the Variables could lose their value.

 

If that is true then I would like to see and example of a Class Module holding one or more Global Variables.

 

I would appreciate any help. I am using Access 97, 2003, and 2007.

 

Regards, Clive.

__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)
.

__,_._,___

Tidak ada komentar:

Posting Komentar