ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Whats the equivalent of null in VBA? (https://www.excelbanter.com/excel-programming/390485-whats-equivalent-null-vba.html)

vivmaha

Whats the equivalent of null in VBA?
 
Hi,
I have the following code:
Public parent As Node
Set parent = New Node
parent = Null

This doesnt work (Error 438). The error is on the last line, where I try to
assign a null value to parent. How do I assign null values to objects in VBA?

Btw, "Node" is defined as a class module.

Thanks.

ron b

Whats the equivalent of null in VBA?
 
try

parent = vbNullString

"vivmaha" wrote:

Hi,
I have the following code:
Public parent As Node
Set parent = New Node
parent = Null

This doesnt work (Error 438). The error is on the last line, where I try to
assign a null value to parent. How do I assign null values to objects in VBA?

Btw, "Node" is defined as a class module.

Thanks.


Gary''s Student

Whats the equivalent of null in VBA?
 
You might want to use something other than parent - might be reserved.
anyway try:
set parent=Nothing
--
Gary''s Student - gsnu200726


"vivmaha" wrote:

Hi,
I have the following code:
Public parent As Node
Set parent = New Node
parent = Null

This doesnt work (Error 438). The error is on the last line, where I try to
assign a null value to parent. How do I assign null values to objects in VBA?

Btw, "Node" is defined as a class module.

Thanks.


FSt1

Whats the equivalent of null in VBA?
 
hi,
try parent = ""

regards
FSt1

"vivmaha" wrote:

Hi,
I have the following code:
Public parent As Node
Set parent = New Node
parent = Null

This doesnt work (Error 438). The error is on the last line, where I try to
assign a null value to parent. How do I assign null values to objects in VBA?

Btw, "Node" is defined as a class module.

Thanks.


JE McGimpsey

Whats the equivalent of null in VBA?
 
First, take a look at Null in VBA Help.

To dissociate object variables from their objects, you set them to
Nothing:

Set parent = Nothing


For most simple cases, that's not really necessary since the object will
be destroyed when the object variable goes out of scope (i.e., when the
Sub exits).


In article ,
vivmaha wrote:

Hi,
I have the following code:
Public parent As Node
Set parent = New Node
parent = Null

This doesnt work (Error 438). The error is on the last line, where I try to
assign a null value to parent. How do I assign null values to objects in VBA?

Btw, "Node" is defined as a class module.

Thanks.


Tim

Whats the equivalent of null in VBA?
 
Set parent = Nothing

Tim

"vivmaha" wrote in message
...
Hi,
I have the following code:
Public parent As Node
Set parent = New Node
parent = Null

This doesnt work (Error 438). The error is on the last line, where I try
to
assign a null value to parent. How do I assign null values to objects in
VBA?

Btw, "Node" is defined as a class module.

Thanks.




vivmaha

Whats the equivalent of null in VBA?
 
I'll try all of these work arounds. I'll only be able to test if they work
when my application is 'semi-complete'.

Why are all of these work arounds? Is there no such 'null' as there is in
other languages?

"vivmaha" wrote:

Hi,
I have the following code:
Public parent As Node
Set parent = New Node
parent = Null

This doesnt work (Error 438). The error is on the last line, where I try to
assign a null value to parent. How do I assign null values to objects in VBA?

Btw, "Node" is defined as a class module.

Thanks.


moon

Whats the equivalent of null in VBA?
 

"Gary''s Student" schreef in
bericht ...
You might want to use something other than parent - might be reserved.
anyway try:
set parent=Nothing
--
Gary''s Student - gsnu200726


And 'Node' is reserved as well.



JLGWhiz

Whats the equivalent of null in VBA?
 
This is the VBA explanation for the term NullString:

Returns or sets the string displayed in cells that contain null values when
the DisplayNullString property is True. The default value is an empty string
(""). Read/write String.



"vivmaha" wrote:

Hi,
I have the following code:
Public parent As Node
Set parent = New Node
parent = Null

This doesnt work (Error 438). The error is on the last line, where I try to
assign a null value to parent. How do I assign null values to objects in VBA?

Btw, "Node" is defined as a class module.

Thanks.


JE McGimpsey

Whats the equivalent of null in VBA?
 
However, Null is different than the null string (look up Null in VBA
Help)


In article ,
JLGWhiz wrote:

This is the VBA explanation for the term NullString:

Returns or sets the string displayed in cells that contain null values when
the DisplayNullString property is True. The default value is an empty string
(""). Read/write String.


Tim

Whats the equivalent of null in VBA?
 

Set someObject = Nothing

is a perfectly normal thing to do *in VBA*: it's not a "workaround".

I suspect that some of the other suggestions you got were from mis-reading
your original question.

Tim

"vivmaha" wrote in message
...
I'll try all of these work arounds. I'll only be able to test if they work
when my application is 'semi-complete'.

Why are all of these work arounds? Is there no such 'null' as there is in
other languages?

"vivmaha" wrote:

Hi,
I have the following code:
Public parent As Node
Set parent = New Node
parent = Null

This doesnt work (Error 438). The error is on the last line, where I try
to
assign a null value to parent. How do I assign null values to objects in
VBA?

Btw, "Node" is defined as a class module.

Thanks.




JMB

Whats the equivalent of null in VBA?
 
They're not really workarounds - just not positive what you are trying to
accomplish. It looks to me like the suggestions using "", vbnullstring, etc
were prompted by you not using a set statement in the example provided (which
is required for objects). It looks like you could be trying to assign null
to a default property of the parent object or you could be trying to destroy
the parent object itself (ie-set it to nothing).




"vivmaha" wrote:

I'll try all of these work arounds. I'll only be able to test if they work
when my application is 'semi-complete'.

Why are all of these work arounds? Is there no such 'null' as there is in
other languages?

"vivmaha" wrote:

Hi,
I have the following code:
Public parent As Node
Set parent = New Node
parent = Null

This doesnt work (Error 438). The error is on the last line, where I try to
assign a null value to parent. How do I assign null values to objects in VBA?

Btw, "Node" is defined as a class module.

Thanks.


NickHK

Whats the equivalent of null in VBA?
 
It seems that your idea that "work arounds" are required stems from your
misunderstanding the VBA/VB language and what Null means.
To me, outside of a database environment, it does not have a real meaning in
VBA, where you have Nothing for objects and Empty for variants (although you
can use Null with a Variant also) & vbNullString for strings.

Private Sub CommandButton1_Click()
Dim Nullable As Variant

Nullable = "some string"
Nullable = Null
Debug.Print IsNull(Nullable)

Nullable = "some string"
Nullable = Empty
Debug.Print IsNull(Nullable)

Dim NullStr As String
NullStr = "Null String"
NullStr = vbNullString
Debug.Print IsNull(NullStr)

End Sub

NickHK

"vivmaha" wrote in message
...
I'll try all of these work arounds. I'll only be able to test if they work
when my application is 'semi-complete'.

Why are all of these work arounds? Is there no such 'null' as there is in
other languages?

"vivmaha" wrote:

Hi,
I have the following code:
Public parent As Node
Set parent = New Node
parent = Null

This doesnt work (Error 438). The error is on the last line, where I try

to
assign a null value to parent. How do I assign null values to objects in

VBA?

Btw, "Node" is defined as a class module.

Thanks.





All times are GMT +1. The time now is 12:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com