共用方式為


VBFixedStringAttribute 類別

更新:2007 年 11 月

表示應將字串視為固定長度。

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

備註

預設 Visual Basic 字串為可變長度。這個屬性 (Attribute) 在使用 Visual Basic 檔案輸入和輸出函式時很有用,例如,需要固定長度字串的 FileGet 和 FilePut。

注意事項:

VBFixedStringAttribute 屬性會指定字串的長度 (以位元組為單位,而非字元)。

範例

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
注意事項:

VBFixedStringAttribute 是資訊性的,而且不能將變數長度字串轉換成固定字串。這個屬性的用途在於修改結構和非區域變數中由辨認 VBFixedStringAttribute 的方法或 API 呼叫使用字串的方式,例如 Len 和 FilePut 函式。請注意,這個屬性不會改變字串本身的實際長度。

智慧型裝置開發人員注意事項

不支援這個類別。

需求

命名空間 (Namespace)︰Microsoft.VisualBasic

組件 (Assembly):Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)

請參閱

概念

Visual Basic 所用的屬性

參考

VBFixedStringAttribute 類別成員

VBFixedArrayAttribute 類別

StringBuilder

MarshalAsAttribute

ComClassAttribute 類別

Len 函式 (Visual Basic)

FileGet 函式

FilePut 函式

FileOpen 函式

其他資源

Visual Basic 中的屬性