簡體   English   中英

如何在一行中聲明和定義自定義類型的變量

[英]How do i declare and define a variable of a custom type in one line

如何在一行中聲明和設置自定義類型。

Option Explicit

Type Stackoverflow
    stack As String
    overflow As String
End Type

Sub WorkingExample()
    Dim example As Stackoverflow
    example.stack = "stack"
    example.overflow = "overflow"
    MsgBox (example.stack + example.overflow)
End Sub

Sub NotCompiling()
    Dim example As Stackoverflow = {.stack = "stack", .overflow = "overflow"}
    MsgBox (example.stack + example.overflow)
End Sub

在這個迷你示例中, WorkingExample顯示了我想要的行為,而NotCompiling部分顯示了我想要寫的內容,但我卻不能。

請說明如何像這個Dim example As Stackoverflow = {.stack = "stack", .overflow = "overflow"}寫成一行。

冒號是一條以回車符結尾的行。

Sub WorkingExample():Dim example As Stackoverflow:example.stack = "stack":example.overflow = "overflow":MsgBox (example.stack + example.overflow):End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM