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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbNullString vs ""

Status
Not open for further replies.

robdon

Programmer
May 21, 2001
252
ES
Hi,

I have noticed in some posts, that poeple use vbNullString to compare strings instead of ""

Is there any difference??

I tend to use "", since its less to type :)

Thanks,

Rob D.
 
For a MS definition, just use VBHelp, Index tab and type in VBNullstring. According to them it should only be used for calling external procedures.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
A "" is nothing, where as a vbnullstring is actually a chr(0). The difference is a byte of data, which is not a lot in normal circumstances. If you want to join an array of 1000 bytes, and you use a null string, the string will be 2000 characters, where as if you use "" the string will be 1000 characters.

BB
 
BB
Could you point me to the reference that gives vbNullString as Chr(0), as that is not my understanding of it.

vbNullChar is Chr(0)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Interesting, from the doco you get

vbNullChar - Chr(0) Character having value 0

vbNullString - String having value 0 Not the same as a zero-length string (""); used for calling external procedures

In VB an equal test between vbnullstring and "" returns true. Would I be right then in saying that a vbnullstring is a zero length string ("") with a null terminator (vbNullChar) which VB does not need but some external procs do eg APIs.

 
Try this comparison...

Private Sub Command1_Click()

MsgBox StrPtr(vbNullString) 'Which equals 0

MsgBox StrPtr("") 'Which does not equal 0

End Sub

For more info on that function check thread222 -740682
 
Thanks guys, thats helped.

Rob D.
 
hi, hope i can join this thread, since i don't think my humble concern's strictly speaking about it, however you be the judge(s):

the following is from some vba code i'm using

Write #intFileNum, rsMyData!Table_Name, rsMyData!Protocol_ID, rsMyData!Patient_ID, rsMyData!Course_ID, _
IIf(rsMyData!AE_Type_Code = 0, "", CLng(rsMyData!AE_Type_Code)), IIf(rsMyData!AE_Grade_Code = 0, "", CInt(rsMyData!AE_Grade_Code)), _
rsMyData!AE_OTHER, IIf(IsNull(rsMyData!AE_Attribution_Code), vbNullString, CInt(Nz(rsMyData!AE_Attribution_Code))), rsMyData!AER_Filed

and it helps to export a csv file that has the following contents based on an a2k table w/ one record...(for testing purposes)

"ADVERSE_EVENTS","T95-0036","A5001","2",10018876,4,"","","1"

what i'm writing about is the fact that what the goal is, is to yield a record that looks like this when the value of the AE_Attribution_Code variable is null (i.e. when the data entry people don't enter anything into the column for it)

"ADVERSE_EVENTS","T95-0036","A5001","2",10018876,4,"",,"1"

someone's suggested using vbNullString but i tend to think it's not any different that entering "" in the same part of the code. is there something that would have the effect of exporting 'nothing' to the export file?

“The philosophy of the school room in one generation will be the philosophy of government in the next." --- Abraham Lincoln
 
You'll probably find that "" and vbNullString differ a bit in the data that is actually contained in the header.

Remember vb is a size prefixed string.
I could see if you looked at the the actual memory map that BSTR header for a vbnullstring would have a 0 size while "" would have a size of 1 because it is actually null terminated. Or vise versa.



Hope I've been helpful,
Wayne Francis

If you want to get the best response to a question, please check out FAQ222-2244 first
 
used vbNullChr -- worked fine.

“The philosophy of the school room in one generation will be the philosophy of government in the next." --- Abraham Lincoln
 
It won't surprise you to know we've discussed this before...thread222-259902
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top