PC Review


Reply
Thread Tools Rate Thread

Check if is nothing

 
 
shapper
Guest
Posts: n/a
 
      30th May 2007
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

 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      30th May 2007
If IsNothing(MyTag) Then
. . .
End If

"shapper" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgQW50b24=?=
Guest
Posts: n/a
 
      30th May 2007
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
>
>

 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgQW50b24=?=
Guest
Posts: n/a
 
      30th May 2007
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >

>
>
>

 
Reply With Quote
 
shapper
Guest
Posts: n/a
 
      30th May 2007
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.com> wrote in message
> >news:(E-Mail Removed)...
> > > 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

 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgQW50b24=?=
Guest
Posts: n/a
 
      30th May 2007
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.com> wrote in message
> > >news:(E-Mail Removed)...
> > > > 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
>
>

 
Reply With Quote
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      30th May 2007
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
 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgQW50b24=?=
Guest
Posts: n/a
 
      30th May 2007
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
>

 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      31st May 2007
> 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?



 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgQW50b24=?=
Guest
Posts: n/a
 
      31st May 2007
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?
>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Spell check -- text marked skip spelling and grammar check =?Utf-8?B?RGF2aWQgQS4=?= Microsoft Word Document Management 8 9th Aug 2008 11:47 PM
Asp.net Treeview Clientscript - Auto Check Child Notes After Check Parent Node Sylvie Microsoft C# .NET 1 9th Oct 2007 02:25 PM
Treeview Clientscript - Auto Check Child Notes After Check Parent Node Sylvie Microsoft ASP .NET 1 9th Oct 2007 02:25 PM
In outlook get message "Spell check cannot check items...try agai =?Utf-8?B?am1yYW5jaG1hbg==?= Microsoft Outlook Discussion 1 28th Sep 2006 10:26 PM
Xp:Check Disk:Tools:Check Now:Both Options:reboot countdown does not complete? RAS Windows XP General 3 1st Feb 2005 06:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:30 AM.