简体   繁体   English

如何在一行中声明和定义自定义类型的变量

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

How can i declare and set 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

In this mini example the WorkingExample shows the behavior i want and the NotCompiling part shows what i want to write but i am not able to. 在这个迷你示例中, WorkingExample显示了我想要的行为,而NotCompiling部分显示了我想要写的内容,但我却不能。

Please show how something like this Dim example As Stackoverflow = {.stack = "stack", .overflow = "overflow"} can be written as one line. 请说明如何像这个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