Results 1 to 2 of 2

Thread: Fixed length String ???????????????

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2001
    Location
    nr Manchester, England
    Posts
    34

    Fixed length String ???????????????

    Hi,

    I need to define a fixed length string in a structure, but not sure how to.

    Any ideas?

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    This is from the help:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width