By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,681 Members | 1,775 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,681 IT Pros & Developers. It's quick & easy.

Check if is nothing

P: n/a
Hello,

I have the following:
If MyTag Is Nothing Then
...
End If

I am getting an error.

MyTag is of type HtmlTextWriterTag

Private MyTag As HtmlTextWriterTag

How can I check if a value was given to MyTag or not?

Thanks,
Miguel

May 30 '07 #1
Share this Question
Share on Google+
12 Replies


P: n/a
If IsNothing(MyTag) Then
. . .
End If

"shapper" <md*****@gmail.comwrote in message
news:11**********************@u30g2000hsc.googlegr oups.com...
Hello,

I have the following:
If MyTag Is Nothing Then
...
End If

I am getting an error.

MyTag is of type HtmlTextWriterTag

Private MyTag As HtmlTextWriterTag

How can I check if a value was given to MyTag or not?

Thanks,
Miguel

May 30 '07 #2

P: n/a
Use "x = Nothing" for value types and "x Is Nothing" for reference types.
This will return true if x is set to it's default value. (a further
complication is that you can use both for strings, but that's a story for
another day).
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
"shapper" wrote:
Hello,

I have the following:
If MyTag Is Nothing Then
...
End If

I am getting an error.

MyTag is of type HtmlTextWriterTag

Private MyTag As HtmlTextWriterTag

How can I check if a value was given to MyTag or not?

Thanks,
Miguel

May 30 '07 #3

P: n/a
That's just another form of "MyTag Is Nothing", which won't work for value
types.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
"Scott M." wrote:
If IsNothing(MyTag) Then
. . .
End If

"shapper" <md*****@gmail.comwrote in message
news:11**********************@u30g2000hsc.googlegr oups.com...
Hello,

I have the following:
If MyTag Is Nothing Then
...
End If

I am getting an error.

MyTag is of type HtmlTextWriterTag

Private MyTag As HtmlTextWriterTag

How can I check if a value was given to MyTag or not?

Thanks,
Miguel


May 30 '07 #4

P: n/a
On May 30, 3:08 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
That's just another form of "MyTag Is Nothing", which won't work for value
types.
--
David Antonwww.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI

"Scott M." wrote:
If IsNothing(MyTag) Then
. . .
End If
"shapper" <mdmo...@gmail.comwrote in message
news:11**********************@u30g2000hsc.googlegr oups.com...
Hello,
I have the following:
If MyTag Is Nothing Then
...
End If
I am getting an error.
MyTag is of type HtmlTextWriterTag
Private MyTag As HtmlTextWriterTag
How can I check if a value was given to MyTag or not?
Thanks,
Miguel
David,

I got lost. You mean I should use:
If MyTag = Nothing Then ...

Is that right?

Thanks,
Miguel

May 30 '07 #5

P: n/a
Exactly. This will work for variable of any value type, including enums.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
"shapper" wrote:
On May 30, 3:08 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
That's just another form of "MyTag Is Nothing", which won't work for value
types.
--
David Antonwww.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI

"Scott M." wrote:
If IsNothing(MyTag) Then
. . .
End If
"shapper" <mdmo...@gmail.comwrote in message
>news:11**********************@u30g2000hsc.googleg roups.com...
Hello,
I have the following:
If MyTag Is Nothing Then
...
End If
I am getting an error.
MyTag is of type HtmlTextWriterTag
Private MyTag As HtmlTextWriterTag
How can I check if a value was given to MyTag or not?
Thanks,
Miguel

David,

I got lost. You mean I should use:
If MyTag = Nothing Then ...

Is that right?

Thanks,
Miguel

May 30 '07 #6

P: n/a
shapper wrote:
Hello,

I have the following:
If MyTag Is Nothing Then
...
End If

I am getting an error.

MyTag is of type HtmlTextWriterTag

Private MyTag As HtmlTextWriterTag

How can I check if a value was given to MyTag or not?

Thanks,
Miguel
HtmlTextWriterTag is an enumeration, so the value can never be Nothing.
A value type always has a value, so you can never check if it has been
given a value or not.

The default value of a HtmlTextWriterTag variable is
HtmlTextWriterTag.Unknown. This is the value that the variable will have
if it has not been assigned any value.

--
Göran Andersson
_____
http://www.guffa.com
May 30 '07 #7

P: n/a
In VB, "Nothing" is always a shortcut to the default value of a type, whether
the type is a ref type or value type. You just have to use "Is" with ref
types and "=" with value types. This is far more general than the C# "null",
which doesn't apply at all to value types.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
"Göran Andersson" wrote:
shapper wrote:
Hello,

I have the following:
If MyTag Is Nothing Then
...
End If

I am getting an error.

MyTag is of type HtmlTextWriterTag

Private MyTag As HtmlTextWriterTag

How can I check if a value was given to MyTag or not?

Thanks,
Miguel

HtmlTextWriterTag is an enumeration, so the value can never be Nothing.
A value type always has a value, so you can never check if it has been
given a value or not.

The default value of a HtmlTextWriterTag variable is
HtmlTextWriterTag.Unknown. This is the value that the variable will have
if it has not been assigned any value.

--
Göran Andersson
_____
http://www.guffa.com
May 30 '07 #8

P: n/a
In VB, "Nothing" is always a shortcut to the default value of a type,
whether
the type is a ref type or value type.
So, how about this...

Dim x As Integer = 0

Will the following produce true?

If x = Nothing then
....
End If

Zero is the default value of an Integer type, yet I have explicitly set its
value to zero, so how could I get a true when testing against Nothing?

May 31 '07 #9

P: n/a
Try it...
When x = 0, "x = Nothing" evaluates to 'True'
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
"Scott M." wrote:
In VB, "Nothing" is always a shortcut to the default value of a type,
whether
the type is a ref type or value type.

So, how about this...

Dim x As Integer = 0

Will the following produce true?

If x = Nothing then
....
End If

Zero is the default value of an Integer type, yet I have explicitly set its
value to zero, so how could I get a true when testing against Nothing?

May 31 '07 #10

P: n/a
Well, I'll be!

I'm not sure I am comfortable with that behavior though.

"David Anton" <Da********@discussions.microsoft.comwrote in message
news:7D**********************************@microsof t.com...
Try it...
When x = 0, "x = Nothing" evaluates to 'True'
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
"Scott M." wrote:
In VB, "Nothing" is always a shortcut to the default value of a type,
whether
the type is a ref type or value type.

So, how about this...

Dim x As Integer = 0

Will the following produce true?

If x = Nothing then
....
End If

Zero is the default value of an Integer type, yet I have explicitly set
its
value to zero, so how could I get a true when testing against Nothing?


May 31 '07 #11

P: n/a
I could write a book on VB weirdness...
The problem is the way VB has developed over the years. It's almost as if
the VB design team has simply responded ad-hoc to user requests, no matter
how half-baked ("why can't I add parentheses to property calls?" "why can't I
omit parentheses on method calls?", "why can't Nothing apply to value
types?", "why do I have to declare my variables?", etc.).
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
"Scott M." wrote:
Well, I'll be!

I'm not sure I am comfortable with that behavior though.

"David Anton" <Da********@discussions.microsoft.comwrote in message
news:7D**********************************@microsof t.com...
Try it...
When x = 0, "x = Nothing" evaluates to 'True'
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
"Scott M." wrote:
In VB, "Nothing" is always a shortcut to the default value of a type,
whether
the type is a ref type or value type.

So, how about this...

Dim x As Integer = 0

Will the following produce true?

If x = Nothing then
....
End If

Zero is the default value of an Integer type, yet I have explicitly set
its
value to zero, so how could I get a true when testing against Nothing?



May 31 '07 #12

P: n/a
David Anton wrote:
I could write a book on VB weirdness...
The problem is the way VB has developed over the years. It's almost as if
the VB design team has simply responded ad-hoc to user requests, no matter
how half-baked ("why can't I add parentheses to property calls?" "why can't I
omit parentheses on method calls?", "why can't Nothing apply to value
types?", "why do I have to declare my variables?", etc.).
Well, the last one would rather be the other way around, as not
declaring the variables was how it was done in BASIC.

"Why can't I declare my variables, as you do in a real programming
language?" ;)

--
Göran Andersson
_____
http://www.guffa.com
May 31 '07 #13

This discussion thread is closed

Replies have been disabled for this discussion.