Local Const String Assignments  Previous topicNext topicFirst topicLast topic



Local Const Strings

Local string constants can be optionally relocated to resource files by converting them to standard strings that are initialized from a resource file. String constants are converted to standard variable length strings because it is not possible to directly assign a resource string to a constant.

For example, this will not work:

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

Example of a local string being converted to a standard string.

Original Source Code Before String Extraction
Option Explicit

Private Sub Form_Load()
  Const MY_STRING = "Welcome to my application."
 
  MsgBox MY_STRING
End Sub


Modified Source Code After String Extraction
Option Explicit

Private Sub Form_Load()
  Dim MY_STRING As String
  MY_STRING = LoadResString(S173_Welcome_to_my_appl)
 
  MsgBox MY_STRING
End Sub

(Note that the Const string assignment has been replaced by a standard string declaration and is initialized by a LoadResString operation. In addition, this string is no longer a read-only constant, it is a dynamic string that could inadvertently be modified by your code in the future.)

Global Const strings are handled differently.