如何在一行中声明和设置自定义类型。
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"}
这样的内容写成一行。
答案 0 :(得分:1)
冒号是一个像回车一样结束的行。
Sub WorkingExample():Dim example As Stackoverflow:example.stack = "stack":example.overflow = "overflow":MsgBox (example.stack + example.overflow):End Sub