Set a type in VBA to nothing?

后端 未结 7 1271
隐瞒了意图╮
隐瞒了意图╮ 2021-02-12 10:40

I have defined a variable with an own type, say

Dim point As DataPoint

Public Type DataPoint
   list as Collection
   name as String
   number as Integer
End Ty         


        
7条回答
  •  说谎
    说谎 (楼主)
    2021-02-12 10:59

    EDIT: Damn! Beaten by JFC :D

    Here is an alternative to achieve that in 1 line ;)

    Dim point As DataPoint
    Dim emptyPoint As DataPoint
    
    Public Type DataPoint
       list As Collection
       name As String
       number As Integer
    End Type
    
    
    Sub Sample()
        '~~> Fill the point
        Debug.Print ">"; point.name
        Debug.Print ">"; point.number
        point.name = "a"
        point.number = 25
        Debug.Print ">>"; point.name
        Debug.Print ">>"; point.number
        '~~> Empty the point
        point = emptyPoint
        Debug.Print ">>>"; point.name
        Debug.Print ">>>"; point.number
    End Sub
    

    SNAPSHOT

    enter image description here

提交回复
热议问题