vbNullString

Digitborn.com

Active Member
Joined
Apr 3, 2007
Messages
353
Hello,

What's the difference when you use vbNullString or "". For example:

TextBox1.Text = " "
TextBox1.Text = "vbNullString"

Are you saving memory or anything else?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
As near as I can tell, you have a space between the quote marks in your first example. If you had put just two quote marks side-by-side without a space in between, then that would be similar to vbNullString.

try this and you will note that putting a space between the quote marks results in a LEN of 1 for cell A1. (By the way, you would not use quote marks around vbNullString as you did in your example)...:

Sub testme()
Range("a1") = " "
Range("a2") = vbNullString
Range("b1") = "=len(a1)"
Range("b2") = "=len(a2)"

End Sub
 
Upvote 0
Hi

Your example should have been this:

Code:
TextBox1.Text = ""  'note no space between quotes!
TextBox1.Text = vbNullString

Close to no difference between them I believe (in the Immediate Window of the VBE try:

?vbNullString=""

wich will return True. The only difference I can find is if you use the StrPtr function eg in the Immediate Window:

?StrPtr(vbNullString)

and

?StrPtr("")

return 2 different values. Does it matter? No idea...
 
Upvote 0
Yes Colin, this link seems to be very useful on the topic.

As I still cannot call myself a programmer, can you tell me if VBA and VB6 are covering 1:1? I mean everything as an example from VB6 can i transform to VBA for Excel, Outlook etc.?
 
Upvote 0
VB6 is VBA but with Windows Forms (more or less I believe) - so VBA is a subset of VB6. With the exception of the Application object models, they should be interchangeable.
 
Upvote 0
They are not identical but VBA and VB6 are very similar (though you don't have the Clipboard, Printer or Screen objects, or resource files). Their implementation of Forms are different though.
 
Last edited:
Upvote 0
I recall running across a thread where a null value in an excel cell is treated differently than "" and there were functions where a null value was ok while "" would produce errors. The issue was that there was no way to reset a null value via Excel formula and I'm wondering if vbNullString could provide a solution.

Perhaps not, since it's likely to be the case that the "" value was a result from an Excel formula and it seems to me that you still can't change it to a null value without deleting the Excel formula.

I guess my question is, assuming vbNullString is a trully null value, i.e. same as the value of an empty cell on a new worksheet, can I use this to create a null function for Excel Formulas to use instead of ""?

Putting = vbNullString directly into a cell isn't recognized (#Name? error). I've never created a function before so I'm only asking (instead of trying it myself) in case I'd be learning how to create a function only to pursue a dead end.
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top