473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Check if is nothing

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
12 1673
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
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: John A Grandy | last post by:
how are people dealing with the situation where a function accepts a String representation of a date ... but a control on the page or form returns a Date value ... strangely, these Date values...
13
by: Dune | last post by:
How do I compare a boolean with Nothing? I can't say "If boolVar Is Nothing" because a boolean is not a reference type, but "If boolVar = Nothing" always seems to return true, even if the...
6
by: SamSpade | last post by:
Public Function PicCreateGraphics() As Graphics 'Client should dispose this PicCreateGraphics = Graphics.FromImage(mDocumentImage) mPicCreateGraphicsSaved = PicCreateGraphics 'Saved so I can...
6
by: Shane Saunders | last post by:
I have a menu option that loads a form and displays infomation. if you go to main form and try to load something else from that same menu, it does a check to see if the form in exist and then...
10
by: Larry Bird | last post by:
I'm trying to check for the presents of null values or null value not being present. My sample code below: If EmailAddresses Is Nothing Then SendMailMessage(EmailAddresses, AlertTitle,...
0
by: Fossie | last post by:
Hi, I need to check that someone signing up is listed in an xml file. I am using a customer membership provider for Access and trying to integrate the xml check into that. Am I on the right track?...
11
by: Joe HM | last post by:
Hello - I have the following very simple code ... Dim lStringA As String = "" Dim lStringB As String = "" .... lStringB = Replace(lStringA, "DUMMY", "", Compare:=CompareMethod.Text)
19
Frinavale
by: Frinavale | last post by:
Filtering user input is extremely important for web programming. If input is left unfiltered users can input malicious code that can cripple your website. This article will explain how to make...
1
by: QuickBooksDev | last post by:
VB.NET 2005 DataGridView Checkbox - Check Event need to know check status I would like to use the DataGridView Checkbox like a normal checkbox. When someone clicks on it I would expect that I...
10
by: Andy B | last post by:
Is it safe to make a method that returns a match collection or nothing? or is it better to just return a match collection and have the code outside the method validate that match collection is...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.