共用方式為


VBFixedStringAttribute Class 

Indicates that a string should be treated as if it were fixed length.

<System.AttributeUsage(System.AttributeTargets.Field, _
   Inherited := False, AllowMultiple := False)> _
Public NotInheritable Class VBFixedStringAttribute
   Inherits System.Attribute

Remarks

Visual Basic strings are of variable length by default. This attribute is useful when using Visual Basic file input and output functions such as FileGet and FilePut that require fixed length strings.

Note

The VBFixedStringAttribute attribute specifies the length of a string in bytes, not characters.

Example

Structure Person
    Public ID As Integer
    Public MonthlySalary As Decimal
    Public LastReviewDate As Long
    <VBFixedString(15)> Public FirstName As String
    <VBFixedString(15)> Public LastName As String
    <VBFixedString(15)> Public Title As String
    <VBFixedString(150)> Public ReviewComments As String
End Structure

Note

The VBFixedStringAttribute is informational and cannot be used to convert a variable length string to a fixed string. The purpose of this attribute is to modify how strings in structures and non-local variables are used by methods or API calls that recognize the VBFixedStringAttribute, such as the Len and FilePut functions. Keep in mind that this attribute does not change the actual length of the string itself.

Smart Device Developer Notes

This class is not supported.

Requirements

Namespace: Microsoft.VisualBasic

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

See Also

Reference

VBFixedStringAttribute Class Members
VBFixedArrayAttribute Class
ComClassAttribute Class
Len Function (Visual Basic)
FileGet Function
FilePut Function
FileOpen Function
StringBuilder
MarshalAsAttribute

Concepts

Attributes Used in Visual Basic

Other Resources

Attributes in Visual Basic