Hi,
I need to define a fixed length string in a structure, but not sure how to.
Any ideas?
:D :D :D
Printable View
Hi,
I need to define a fixed length string in a structure, but not sure how to.
Any ideas?
:D :D :D
This is from the help:Quote:
Upgrade Recommendation: Avoid Arrays and Fixed-Length Strings in User-Defined TypesSee Also
Language Recommendations for Upgrading
Due to changes made which allow Visual Basic .NET arrays and structures (formerly known as user-defined types) to be fully compatible with other Visual Studio .NET languages, fixed-length strings are no longer supported in the language. In most cases this is not a problem, because there is a compatibility class which provides fixed-length string behavior, so the code:
Dim MyFixedLengthString As String * 100
upgrades to the following:
Dim MyFixedLengthString As New VB6.FixedLengthString(100)
However, fixed-length strings do cause a problem when used in structures. The problem arises because the fixed-length string class is not automatically created when the structure is created. Likewise, fixed-size arrays are not created when the structure is created.
When your code is upgraded, user-defined types with fixed-length strings or arrays will be converted to structures and marked with a comment telling you to initialize the fixed-length string or array before referencing the structure in code. However, you can shield yourself from this modification by changing your Visual Basic 6.0 user-defined types to use strings instead of fixed-length strings, and uninitialized arrays instead of fixed-size arrays. For example:
Private Type MyType
MyArray(5) As Integer
MyFixedString As String * 100
End Type
Sub Bar()
Dim MyVariable As MyType
End Sub
can be changed to:
Private Type MyType
MyArray() As Integer
MyFixedString As String
End Type
Sub Bar()
Dim MyVariable As MyType
ReDim MyVariable.MyArray(5) As Integer
MyVariable.MyFixedString = String$(100, " ")
End Sub