本文介绍了如何在一行中声明和定义自定义类型的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在一行中声明和设置自定义类型.

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

在这个迷你示例中,WorkingExample显示了我想要的行为,而NotCompiling部分显示了我想写的内容,但我却不能.

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.

请说明如何将这样的Dim example As Stackoverflow = {.stack = "stack", .overflow = "overflow"}内容写成一行.

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

推荐答案

冒号是一条以回车符结尾的行.

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

这篇关于如何在一行中声明和定义自定义类型的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 10:22