Relocation Of Global Constants  Previous topicNext topicFirst topicLast topic



Relocation Of Global String Constants
Global string constants can be optionally relocated to resource files by converting them to read-only properties that are retrieved from a resource file. String constants are converted to read-only properties because it is not possible to directly assign a resource string to a constant.

For example, this will NOT work:

Const SYSTEM_STRING = LoadResString(101) 'This will generate an error!

Example of a global string being converted to a read-only property.

Original Source Code Before String Extraction
Option Explicit

Const SYSTEM_STRING = "Login Error"

Private Sub Form_Load()
  Me.Caption = "Title"
  Debug.Print "Form Loaded"
End Sub


Modified Source Code After String Extraction
Option Explicit

Private Sub Form_Load()
  Me.Caption = LoadResString(S101_Title)
  Debug.Print "Form Loaded"
End Sub

'This was: Global Const SYSTEM_STRING = "Login Error"
Property Get SYSTEM_STRING() As String
SYSTEM_STRING = LoadResString(S173_Login_Error)
End Property

(Note that the Const string assignment has been replaced by a read-only property and that it has been repositioned from the beginning of the module to the bottom of the module. Any #If conditional compile switches that were in effect are also maintained.)

Local Const strings are handled differently.