Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set a type in VBA to nothing?

Tags:

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 Type 

and I want to delete all values of the variable point at once. If it was a class, I would just use Set point = New DataPoint, or set Set point = Nothing, but how can I proceed if it's a type?

like image 920
tyrex Avatar asked Mar 20 '12 14:03

tyrex


People also ask

How do you set a variable to nothing in VBA?

Assigning Nothing To free an object variable so that it no longer points to anything, assign the "Nothing" keyword. (eg Set rgeRange = Nothing). It is good programming practice to free object variables when they are no longer needed, since this can save resources.

Is nothing then in VBA?

There is no isNothing() function in VBA (see is… () functions).

WHAT IS SET command in VBA?

“Set”, is a keyword used in VBA programming to assign a reference to an object or cell range which is going to remain fix throughout the program or code in Excel. VBA Set basically helps us in avoiding repetitive input of range we need to select while executing the code.


1 Answers

You can benefit from the fact that functions in VB have an implicit variable that holds the result, and that contains the default type value by default.

public function GetBlankPoint() as DataPoint end function 

Usage:

point = GetBlankPoint() 
like image 174
GSerg Avatar answered Oct 16 '22 14:10

GSerg