Credits goes to Plutonix for giving a working/workable solution in a comment.
Used the following approach when I made large use of Modules long ago.
Add a Public Module to your Project :
Public Module MyConsts
' Define your constant Char
Public Const vbTabC As Char = Microsoft.VisualBasic.Chr(9) ' For Tabulation
Public Const vbEMC As Char = Microsoft.VisualBasic.Chr(25) ' For EM (End of Medium)
' ^^ if you know the ASCII Char Code.
' Use Microsoft.VisualBasic.ChrW() for Unicode (unsure of that)
Public Const vbCharQM As Char = "?"c
Public Const vbComma As Char = ","c
Public Const vbDot As Char = "."c
' or
Public Const vbCharQM2 As Char = CChar("?")
' ^^ if you can actually write the char as String in the Compiler IDE
End Module
Then use the constants identifier anywhere in your project like any VB constant string, but, they are of type Char
of course (To combine them with String
, you'll have to use .ToString()
)
Public Sub TestConstChar()
MessageBox.Show("[" + vbEMC.ToString() + "]")
' But hey ! What's the purpose of using End of Medium Char ?
End sub
Note that you have Environment.NewLine
that automatically returns the valid Line Feed, or Carriage Return/Line Feed, or only Carriage Return, or even another control Char/String/Stream that is on use on your Operating System.
Based on the Environment.NewLine
example, you can also define a (wandering) Class
Public Class MyConstChars
Public Shared ReadOnly Property Tab() As Char
Get
Return Microsoft.VisualBasic.ControlChars.Tab
End Get
End Property
' ...
End Class
' And use it anywhere like myString = "1" + MyConstChars.Tab.ToString() + "One"
This approach allows you to have more control over the actual value of the static/shared Property, like with Environment.NewLine, and allows your Class to propose much more options (Members) than a simple Constant. However, writing the LambdaClassName.LambdaClassProperty isn't very intuitive I reckon.
One another way to ease coding by using constant tags/identifiers in the IDE is to define Code Templates. A code template (piece of code) can be defined in the options of your IDE. You may already know what it is about : you type a keyword, then the IDE replace that keyword with one block of code (that you use often enough to require that shortcut) That's what is happening when you redefines (Overrides) a .ToString()
Function in classes.
' I have for example one code template keyword...
PlaceholderChecker
' ...that generates the following Code :
#If IsDebugMode Then
''' <summary>
''' Placeholder Routine to check wether ALL Class Components are included in Solution.
''' </summary>
Private Shared Sub PlaceholderChecker()
p_ClassVariableName_ClassPartialSuffix = True
End Sub
#End If
In some cases, you don't have to define constants - or have to write more complex code - to get where you want.