Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which is better "" or Empty 3

Status
Not open for further replies.

Brawn

Programmer
Jul 5, 2001
73
0
0
CA

Which is better to use:

Code:
string = ""
or
Code:
string = Empty

Pros?
Cons?
[smile] Brawn

"My mind is my Shrine,
and my body the Temple around it."

-The difference between genius and stupidity is that genius has its limits-
 
Yes, with-out reading you code I already know what you want to say here (I was thinking about mentioning it also but then thought better to drop it - it didn't concern the question and the point was covered as far as speed - the only difference that was needed to be pointed out here). But seeing's how you did it anyways then "cheers" - some who read your and my comments may profit from them.

When you declare a string variable and, with-out initalizing it, it will hold a Null and can be passed as such, it gets passed as a NULL and not as a string variable with zero length.

To see this declare a variable as a string (Dim s As String) and use the StrPtr function:

Debug.Print StrPtr(s) and then do the same after assigning the variable ""

This means that if I declare a variable as String - I can pass it to a DLL function that requires it - but once I assign a value to the string - even "" - it will not work anymore.

To advoid mis-understandings - or errors I should say - it is best to pass a variable set to vbNullString, or just the vbNullString constant itself.

Some DLL procedures possibly expect a string or a Null value as argment. When a Null pointer to a string needs to be passed, then the argument needs to be declared As String and the constant vbNullstring needs assigned, or just the constant itself (VB)

Passing a string with the length of Null ("" ) doesn't work because the pointer to a Null String gets passed whose value itself isn't Null. Therefore a argumkent with a Real Null value needs to be passed - and that is done by passing vbNullString or passing a unassigned string.......

I would say let's close out this chapter - the points have been made and past mis-understandings have been cleared up - I hope - and possibly new ones created - and I hope the real message in the post hasn't gone under.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top