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

眉间皱痕 提交于 2019-12-13 05:14:32

问题


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.

Please show how something like this Dim example As Stackoverflow = {.stack = "stack", .overflow = "overflow"} can be written as one line.


回答1:


The colon is a line ending like a carriage return.

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


来源:https://stackoverflow.com/questions/24952167/how-do-i-declare-and-define-a-variable-of-a-custom-type-in-one-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!