Hi guys, quick sanity check please.

When TESTING for nothing, it's "if <expr> Is Nothing"

when ASSIGNING, it's "<expr> = Nothing"

correct ?

so a line "If ThisValue = nothing" in some (inherited) code is a bug, plain
& simple ?

Thanks

Re: = nothing vs. Is Nothing by Armin

Armin
Thu May 08 03:24:04 CDT 2008

"Jethro" <jethro_uk@hotmail.com> schrieb
> Hi guys, quick sanity check please.
>
> When TESTING for nothing, it's "if <expr> Is Nothing"
>
> when ASSIGNING, it's "<expr> = Nothing"
>
> correct ?
>
> so a line "If ThisValue = nothing" in some (inherited) code is a
> bug, plain & simple ?

No, not a bug, but IMO an undesired feature. Nothing used with value
types is the "default value" of the value type, i.e. zero for Integers,
1/1/0001 with Dates, etc.

"If ThisValue = nothing" only works with values types (not with
reference types), so if ThisValue is an Integer, it is equal to "If
ThisValue = 0"

...But, what about putting the caret on the word Nothing and pressing
[F1]? ;-)


AZ


Re: = nothing vs. Is Nothing by Cor

Cor
Thu May 08 05:28:53 CDT 2008

The nicest example is in my opinion a string

A string that Is nothing, is not yet assigned

A string that = nothing is the same as "" and will direct before the
evaluating set to that if it "Is" nothing

This finer test is not in C* languages.

Cor




"Jethro" <jethro_uk@hotmail.com> schreef in bericht
news:kYmdnSbuX5YkLb_VnZ2dnUVZ8tuqnZ2d@bt.com...
> Hi guys, quick sanity check please.
>
> When TESTING for nothing, it's "if <expr> Is Nothing"
>
> when ASSIGNING, it's "<expr> = Nothing"
>
> correct ?
>
> so a line "If ThisValue = nothing" in some (inherited) code is a bug,
> plain
> & simple ?
>
> Thanks
>


Re: = nothing vs. Is Nothing by DavidAnton

DavidAnton
Thu May 08 09:53:00 CDT 2008

That's quite correct - with one addition: to make things a little more
confusing, "If s = Nothing" and "If s Is Nothing" both work for strings, with
subtly different results...
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
Java to VB & C#
Instant C#: convert VB to C#
Instant VB: convert C# to VB
Instant C++: VB, C#, or Java to C++/CLI


"Armin Zingler" wrote:

> "Jethro" <jethro_uk@hotmail.com> schrieb
> > Hi guys, quick sanity check please.
> >
> > When TESTING for nothing, it's "if <expr> Is Nothing"
> >
> > when ASSIGNING, it's "<expr> = Nothing"
> >
> > correct ?
> >
> > so a line "If ThisValue = nothing" in some (inherited) code is a
> > bug, plain & simple ?
>
> No, not a bug, but IMO an undesired feature. Nothing used with value
> types is the "default value" of the value type, i.e. zero for Integers,
> 1/1/0001 with Dates, etc.
>
> "If ThisValue = nothing" only works with values types (not with
> reference types), so if ThisValue is an Integer, it is equal to "If
> ThisValue = 0"
>
> ....But, what about putting the caret on the word Nothing and pressing
> [F1]? ;-)
>
>
> AZ
>
>

Re: = nothing vs. Is Nothing by Jethro

Jethro
Thu May 08 10:25:13 CDT 2008

"Cor Ligthert[MVP]" <notmyfirstname@planet.nl> wrote in message
news:4F5745FF-BD74-4255-9017-40E87BAF7F64@microsoft.com...
> The nicest example is in my opinion a string
>
> A string that Is nothing, is not yet assigned
>
> A string that = nothing is the same as "" and will direct before the
> evaluating set to that if it "Is" nothing
>
> This finer test is not in C* languages.
>
> Cor
>
>
>
>
> "Jethro" <jethro_uk@hotmail.com> schreef in bericht
> news:kYmdnSbuX5YkLb_VnZ2dnUVZ8tuqnZ2d@bt.com...
>> Hi guys, quick sanity check please.
>>
>> When TESTING for nothing, it's "if <expr> Is Nothing"
>>
>> when ASSIGNING, it's "<expr> = Nothing"
>>
>> correct ?
>>
>> so a line "If ThisValue = nothing" in some (inherited) code is a bug,
>> plain
>> & simple ?
>>
>> Thanks
>>
>

The problem I was having was a test on an integer, which had a value of 0
was equating to true ...

Dim myInt as integer =0

if myInt = Nothing then MessageBox("myInt is showing as 'Nothing' even
thought is has a vallue of 0")

seems to print the MessageBox .....


Re: = nothing vs. Is Nothing by Cor

Cor
Thu May 08 10:38:06 CDT 2008

David,

Maybe easier, "Is" is testing a Type and "=" a value.

While "Is" nothing means in fact no object, because everything is inheriting
from object, this goes forever.

Therefore it is If dr.Items("whatever") Is DBNull.Value then the type
DBNull.Value is tested.

While If CInt(dr.Items("whatever")) = 0 then the value zero is tested.

Cor

"David Anton" <DavidAnton@discussions.microsoft.com> schreef in bericht
news:831E24ED-2CEF-45D2-805A-8DE01EA3CDDC@microsoft.com...
> That's quite correct - with one addition: to make things a little more
> confusing, "If s = Nothing" and "If s Is Nothing" both work for strings,
> with
> subtly different results...
> --
> http://www.tangiblesoftwaresolutions.com
> C++ to C#
> C++ to VB
> C++ to Java
> Java to VB & C#
> Instant C#: convert VB to C#
> Instant VB: convert C# to VB
> Instant C++: VB, C#, or Java to C++/CLI
>
>
> "Armin Zingler" wrote:
>
>> "Jethro" <jethro_uk@hotmail.com> schrieb
>> > Hi guys, quick sanity check please.
>> >
>> > When TESTING for nothing, it's "if <expr> Is Nothing"
>> >
>> > when ASSIGNING, it's "<expr> = Nothing"
>> >
>> > correct ?
>> >
>> > so a line "If ThisValue = nothing" in some (inherited) code is a
>> > bug, plain & simple ?
>>
>> No, not a bug, but IMO an undesired feature. Nothing used with value
>> types is the "default value" of the value type, i.e. zero for Integers,
>> 1/1/0001 with Dates, etc.
>>
>> "If ThisValue = nothing" only works with values types (not with
>> reference types), so if ThisValue is an Integer, it is equal to "If
>> ThisValue = 0"
>>
>> ....But, what about putting the caret on the word Nothing and pressing
>> [F1]? ;-)
>>
>>
>> AZ
>>
>>


Re: = nothing vs. Is Nothing by Cor

Cor
Thu May 08 10:46:59 CDT 2008


> Dim myInt as integer =0
>
> if myInt = Nothing then MessageBox("myInt is showing as 'Nothing' even
> thought is has a vallue of 0")
>
> seems to print the MessageBox .....

Yes of course because the default for an integer (Nothing) = 0,

If 0 = 0 then ................... is true

While this goes as well and is more VB style

Dim myInt as integer
if myInt = nothing then the messagebox will be showed, because myint is set
forever in this case to the default 0

Cor


Re: = nothing vs. Is Nothing by Karl

Karl
Thu May 08 14:32:18 CDT 2008

On 8 May, 16:46, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl> wrote:
> > Dim myInt as integer =0
>
> > if myInt = Nothing then MessageBox("myInt is showing as 'Nothing' even
> > thought is has a vallue of 0")
>
> > seems to print the MessageBox .....
>
> Yes of course because the default for an integer (Nothing) = 0,
>
> If 0 = 0 then ................... is true
>
> While this goes as well and is more VB style
>
> Dim myInt as integer
> if myInt = nothing then the messagebox will be showed, because myint is set
> forever in this case to the default 0
>
> Cor

If you're using VB the why not use the IsNothing Method?

if IsNothing(myInt) then MessageBox.Show....

Re: = nothing vs. Is Nothing by Armin

Armin
Thu May 08 15:36:57 CDT 2008

"Karl Rhodes" <googlegroups@cortexa.co.uk> schrieb
> If you're using VB the why not use the IsNothing Method?
>
> if IsNothing(myInt) then MessageBox.Show....

Why call a function that does the comparision instead of doing the
comparison?


Armin


Re: = nothing vs. Is Nothing by Jethro

Jethro
Fri May 09 02:54:13 CDT 2008

"Karl Rhodes" <googlegroups@cortexa.co.uk> wrote in message
news:c1bcba36-f2a2-4065-9479-7f60575f232f@r66g2000hsg.googlegroups.com...
> On 8 May, 16:46, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl> wrote:
>> > Dim myInt as integer =0
>>
>> > if myInt = Nothing then MessageBox("myInt is showing as 'Nothing' even
>> > thought is has a vallue of 0")
>>
>> > seems to print the MessageBox .....
>>
>> Yes of course because the default for an integer (Nothing) = 0,
>>
>> If 0 = 0 then ................... is true
>>
>> While this goes as well and is more VB style
>>
>> Dim myInt as integer
>> if myInt = nothing then the messagebox will be showed, because myint is
>> set
>> forever in this case to the default 0
>>
>> Cor
>
> If you're using VB the why not use the IsNothing Method?
>
> if IsNothing(myInt) then MessageBox.Show....


As I said, inherited code...


Re: = nothing vs. Is Nothing by Cor

Cor
Fri May 09 08:13:21 CDT 2008


>
> As I said, inherited code...

No you said,

>so a line "If ThisValue = nothing" in some (inherited) code is a bug,
plain & simple ?

The "Is" is about objects, while you can test everything as object, as that
is the base for every class in Net.
(The so often used ToString is a method from object and therefore a method
from everything).

If this Value = nothing has nothing to do with inherited code.

However why did you get the idea that this is a bug?

Cor


Re: = nothing vs. Is Nothing by Jethro

Jethro
Fri May 09 09:59:37 CDT 2008

"Cor Ligthert[MVP]" <notmyfirstname@planet.nl> wrote in message
news:39F15764-FA45-482B-8380-C33186A49AEF@microsoft.com...
>
>>
>> As I said, inherited code...
>
> No you said,
>
> >so a line "If ThisValue = nothing" in some (inherited) code is a bug,
> plain & simple ?
>
> The "Is" is about objects, while you can test everything as object, as
> that is the base for every class in Net.
> (The so often used ToString is a method from object and therefore a method
> from everything).
>
> If this Value = nothing has nothing to do with inherited code.
>
> However why did you get the idea that this is a bug?

ROTFL !

Sorry, bad choice of words. What I meant is that I have just started a new
job, and am picking up the code left by the previous developer - therefore
*I* "inherited" it.

Nice to go home with a laugh - thanks for your input, hope you have a good
weekend !