Until VB.Net doesn't define specific directives to stop
and start
VB.Net code formatting, it is impossible to align similar lines as in a table.
Since what I search is that messages of application are easily readable, I have written a little Text Template (T4 tools in Visual Studio 2019) that automatically generates my VB.NET code.
The VB.Net code is always NOT ALIGNED; but .TXT source file that is used by T4 tools to generate VB.NET code is aligned.
.TXT file that contains all messages is following
+----------------------------------------+------+------------------------------------------------------------------------------------------
| CMD_PARAMETER_IS_NULL | 1001 | [%s] command's parameter [%s] cannot be null
| CMD_PARAMETER_IS_EMPTY | 1002 | [%s] command's parameter [%s] cannot be empty
| ERROR_WHEN_OPENING_OUPUT_FILE | 1003 | Error when opening OUTPUT file [%s]
| ORACLE_ERROR_ON_ALTER_SESSION | 1004 | Oracle error when executing ALTER SESSION
| ORACLE_ERROR_IN_OPEN_DB | 1005 | Oracle error in OPEN-DB= new XMsg()
| ZIP_ERROR_ON_CALC_CHAIN | 1006 | ZIP error on CALC-CHAIN
.TT file that generates VB.NET code is following
<#@ template debug="false" hostspecific="false" language="VB" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".vb" #>
Public Partial Class M
<#
Dim iPos = 1
Dim sLine As String
Dim sVariableName As String = "?"
Dim iVariableNamePos As Integer
Dim iVariableNameLen As Integer
Dim sMsgNo As Integer
Dim iMsgNoPos As Integer
Dim iMsgNoLen As Integer
Dim sNrVariables As String
Dim sMessage As String = "?"
Dim iMessagePos As Integer
Dim bColumnPosInitialized = False
Dim sr as StreamReader = New StreamReader(".\Sources\Messages.txt", Encoding.Default)
Do While True
sLine = sr.ReadLine
If sLine is Nothing then
Exit Do
End If
If sLine.StartsWith("+") Then
If Not bColumnPosInitialized Then
bColumnPosInitialized = True
iVariableNamePos = sLine.IndexOf("+") + 2
iMsgNoPos = sLine.IndexOf("+", iVariableNamePos + 1) + 2
iMessagePos = sLine.IndexOf("+", iMsgNoPos + 1) + 2
iVariableNameLen = iMsgNoPos - iVariableNamePos - 3
iMsgNoLen = iMessagePos - iMsgNoPos - 3
End If
Else
If sLine.StartsWith("|") Then
sLine &= " "
sNrVariables = "0"
sVariableName = sLine.Substring(iVariableNamePos, iVariableNameLen).Trim
sMsgNo = sLine.Substring(iMsgNoPos, iMsgNoLen).Trim
sMessage = sLine.Substring(iMessagePos).Trim
If sMessage.Contains("[%s]") Then
sNrVariables = "1"
End If
#>
Shared <#= "MSG_" & sMsgNo & "_" & sVariableName #> = New XMsg(<#= sMsgNo #>, <#= sNrVariables #>, "%", "<#= sMessage #>")
<#
End If
End If
Loop
sr.Close()
#>
End Class
and generated VB.Net source code is following
Public Partial Class M
Shared MSG_1001_CMD_PARAMETER_IS_NULL = New XMsg(1001, 1, "%", "[%s] command's parameter [%s] cannot be null")
Shared MSG_1002_CMD_PARAMETER_IS_EMPTY = New XMsg(1002, 1, "%", "[%s] command's parameter [%s] cannot be empty")
Shared MSG_1003_ERROR_WHEN_OPENING_OUPUT_FILE = New XMsg(1003, 1, "%", "Error when opening OUTPUT file [%s]")
Shared MSG_1004_ORACLE_ERROR_ON_ALTER_SESSION = New XMsg(1004, 0, "%", "Oracle error when executing ALTER SESSION")
Shared MSG_1005_ORACLE_ERROR_IN_OPEN_DB = New XMsg(1005, 0, "%", "Oracle error in OPEN-DB= new XMsg()")
Shared MSG_1006_ZIP_ERROR_ON_CALC_CHAIN = New XMsg(1006, 0, "%", "ZIP error on CALC-CHAIN")
End Class
The .TT source file is currently a propotyp without syntax check and some limitation. But this is another story.