I want to see typed structures of which the elements can be constants, variables (including read-only and array), read-only properties, other structures, and custom data types.
Also… VB currently allows you to declare a variable/constant of a structure type only at the module and local levels. I want to be able to declare global variables of a structure (and enumeration) type.
What is the reason behind this ? Because you can do this with a Shared Class.
The only real difference is that the class is heap allocated and the structure is stack allocated.
(Only trying to understand the reasoning)
About the global variables - Can you do that? How?
Here is an example of one using read-only properties…
''' <summary>Returns information regarding the most previous exception or runtime error.</summary>
Public Structure PreviousError
''' <summary>Returns an indication of whether the previous adverse event is expected (an exception) or is unexpected (a runtime error).</summary>
''' <value>Returns a boolean value of True if the event is expected (an exception). Returns a value of False if the event is unexpected (a runtime error). Returns a value of False in the event of an error.</value>
''' <remarks></remarks>
Public Shared ReadOnly Property Expected() As System.Boolean = m_blnExpP
''' <summary>Returns the name of the data field (variable, constant, type structure, type enumeration, etc.) involved with the previous exception or error.</summary>
''' <summary>Returns the path to the previous exception or error's corresponding help file.</summary>
''' <value>Returns a string value containing the path to the help file. Returns an empty value if no path is specified. Returns an empty value in the event of an error.</value>
''' <remarks></remarks>
Public Shared ReadOnly Property HelpFile() As System.String = m_strHlpP
''' <summary>Returns a topic keyword within an associated help file, the topic of which corresponds to the previous exception or error.</summary>
''' <value>Returns a string value containing the help topic keyword for the exception or error. Returns an empty value if no keyword is specified. Returns an empty value in the event of an error.</value>
''' <remarks></remarks>
Public Shared ReadOnly Property HelpKeyword() As System.String = m_strKeyP
''' <summary>Returns the name of the object or code library within which the previous exception or error is raised.</summary>
''' <value>Returns a string value containing the name of the object or code library in which the exception or error is raised. Returns an empty value if the source cannot be determined. Returns an empty value in the event of an error.</value>
''' <remarks></remarks>
Public Shared ReadOnly Property Library() As System.String = m_strLibP
''' <summary>Returns a unique numeric code used to identify the previous exception or error.</summary>
''' <value>Returns an integer value containing a numeric code which corresponds to the exception or error. Returns a value of zero if no error is raised. Returns a value of zero in the event of an error.</value>
''' <remarks></remarks>
Public Shared ReadOnly Property Number() As System.Int64 = m_lngNumP
''' <summary>Returns the name of the routine, property, or event which raised the previous exception or error.</summary>
''' <value>Returns a string value containing the name of the routine that raised the exception or error. Returns an empty value if the source cannot be determined. Returns an empty value in the event of an error.</value>
''' <remarks></remarks>
Public Shared ReadOnly Property Routine() As System.String = m_strRtnP
''' <summary>Returns text which briefly summarizes the previous exception or error.</summary>
''' <value>Returns a string value containing the text summary of the exception or error. Returns an empty value if no description is determined. Returns an empty value in the event of an error.</value>
''' <remarks></remarks>
Public Shared ReadOnly Property Summary() As System.String = m_strSumP
End Structure
You can’t currently do global variables that are declared as a structure type in VB. I would not have the first idea of how to implement such a feature.
Oh. In VB you can declare a global variable using the “Public” keyword as long as it is one of the intrinsic (built-in) data types or managed object. i.e., String, Integer, Long, etc…
Just declare it in any standard module. You can’t declare a global variable in a form or class module.
Public m_frmMain As System.Windows.Forms.Form 'A proxy instance of the main form object.
The purpose of creating structures is to minimally encapsulate related constants, variables, etc. and create namespaces for them without the burden of creating a class.
Friend Structure Names
''' <summary>Names; first name.</summary>
Friend Const FirstName As System.String = "Gypsy"
''' <summary>Names; last name.</summary>
Friend Const LastName As System.String = "Prince"
End Structure
Dim namFirst As Names
Dim namLast As Names
namFirst = Names.FirstName
namLast = Names.LastName
MsgBox("My name is " & namFirst & namLast & ".") 'Displays "My name is GypsyPrince."