Johannes
Johannes

Reputation: 6717

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.

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

Upvotes: 0

Views: 519

Answers (1)

D.Ddgg
D.Ddgg

Reputation: 91

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

Upvotes: 1

Related Questions