Re: Selecting Proper Variables

From: Herfried K. Wagner [MVP] (hirf-spam-me-here_at_gmx.at)
Date: 08/29/04


Date: 29 Aug 2004 15:57:53 +0200


* "Cor Ligthert" <notfirstname@planet.nl> scripsit:
>>> MyString.empty
>>> myString = Nothing
>>> myString = ""
>>> Are all the same
>>
>> They are not the same, 'Nothing' is a null reference, 'Empty', or '""'
>> are not.
>>
> did I write Is Nothing?
> Although = Nothing acts the same as Is nothing when there is no reference.

\\\
Dim s1 As String = String.Empty
MsgBox(s1.Length) ' 0.
Dim s2 As String = Nothing
MsgBox(s2.Length) ' 'NullReferenceException'.
///

That's what I was talking about. If you compare a string that is
holding a null reference to 'String.Empty', you will receive a 'True' as
the result of the comparison. Nevertheless, both string variables
behave differently.

-- 
 M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
 V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>


Relevant Pages

  • Re: My VB6 MS Word VBA code crashes Word - Word97
    ... The reason you can't go backwards (that is, compile with a reference to Word ... Dim oWord As Word.Application ' Note early bound is OK here! ... Set oDocuments = oApplication.Documents ' Note this is an early bound ... >>> Dim Firstname As String ...
    (microsoft.public.word.vba.general)
  • Re: String Reference Type
    ... Dim x As New MyInt ... The 'pointer' (lets call it a reference shall we) returned by the New ... Therefore its always allocated in the heap and a variable of string type is ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Search and Delete Files Based on Mask
    ... If you're not familiar with VB you can reference the KB article for complete ... Dim fso As New FileSystemObject ... Dim sDir As String, sSrchString As String ... fso.DeleteFile (filespec[, force]); ...
    (comp.programming)
  • Re: Send Word Data to Excel
    ... Did you create the Reference to Microsoft Scripting Runtime? ... Dim oWordApp As Word.Application ... Dim FileArrayAs String ... MsgBox "A folder was not selected" ...
    (microsoft.public.word.vba.general)
  • Re: empty vs null
    ... The documentation you refer to is for the System.String type, ... though they moved to being immutable reference types. ... to Vb.NET, suddenly we could actually compare string references, and at the same ... > references compare equal to each other. ...
    (microsoft.public.dotnet.languages.vb)