473,708 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comparing Empty Value types

I have a public variable in a class of type color declared as follows:

public mycolor as color = color.Empty

I want to check to see if the user has specified a color like;

if mycolor = Color.Empty then.....
or
if mycolor is Color.Empty then .......

I get errors saying that = can be used for colors and is can't be used with
value types. I give up...how do I do this. Thanks.
--
Dennis in Houston
Nov 21 '05 #1
19 2650
Since ValueType derives from Object, you can use the Equals method. For
Value Types, this returns true if the instances are of the same type and
have the same value.

If mycolor.Equals( Color.Empty) Then
MessageBox.Show ("mycolor is Empty")
End If

hope that helps..
Imran.
"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:9A******** *************** ***********@mic rosoft.com...
I have a public variable in a class of type color declared as follows:

public mycolor as color = color.Empty

I want to check to see if the user has specified a color like;

if mycolor = Color.Empty then.....
or
if mycolor is Color.Empty then .......

I get errors saying that = can be used for colors and is can't be used
with
value types. I give up...how do I do this. Thanks.
--
Dennis in Houston

Nov 21 '05 #2
Dennis,
Did you try the Equals function or the Equals Operator?

If mycolor.Equals( Color.Empty) Then

End If

To use the Equals Operator you need to call the shared function that is
created.

If Color.op_Equali ty(mycolor, Color.Empty) Then

End If

See the Color.Equals function in the online help for some important remarks
about using Color.Equals and when you may want to use Color.ToArgb to
compare two colors.

If mycolor.ToArgb( ) = Color.Empty.ToA rgb() Then

End If
NOTE: VS.NET 2005 (aka Whidbey, due out later in 2005) will support calling
the Equals Operator with the familiar "=" syntax. For information on VS.NET
2005 see http://lab.msdn.microsoft.com/vs2005/.

' VS.NET 2005 sample
If mycolor = Color.Empty Then

End If

Hope this helps
Jay

"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:9A******** *************** ***********@mic rosoft.com...
I have a public variable in a class of type color declared as follows:

public mycolor as color = color.Empty

I want to check to see if the user has specified a color like;

if mycolor = Color.Empty then.....
or
if mycolor is Color.Empty then .......

I get errors saying that = can be used for colors and is can't be used
with
value types. I give up...how do I do this. Thanks.
--
Dennis in Houston

Nov 21 '05 #3
Dennis,

As alternative
If mycolor.ToArgb = mycolor.Empty.T oArgb

End if

Cor

"Dennis" <De****@discuss ions.microsoft. com>:

public mycolor as color = color.Empty

I want to check to see if the user has specified a color like;

if mycolor = Color.Empty then.....
or
if mycolor is Color.Empty then .......

I get errors saying that = can be used for colors and is can't be used
with
value types. I give up...how do I do this. Thanks.
--
Dennis in Houston

Nov 21 '05 #4
"Cor Ligthert" <no************ @planet.nl> schrieb:
As alternative
If mycolor.ToArgb = mycolor.Empty.T oArgb


This only works for 'Color'. I would stick with the more general pattern of
using 'Equals'...

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

Nov 21 '05 #5
"Herfried K. Wagner [MVP]"
As alternative
If mycolor.ToArgb = mycolor.Empty.T oArgb
This only works for 'Color'. I would stick with the more general pattern
of using 'Equals'...


You are free to do that. I will not blaim you for that.

However I use this one, I find it nicer just a personal choise

May I do that as well?

:-)

Cor
Nov 21 '05 #6
Cor (& Herfried),
As I stated in my initial reply:
See the Color.Equals function in the online help for some important
remarks about using Color.Equals and when you may want to use Color.ToArgb
to compare two colors.
If I want to compare what is visible seen I will use Color.ToArgb in other
words to compare the Alpha, Red, Green & Blue values.

If I want to compare what is literally used I will use Color.Equals or
Color.op_Equali ty, in other words to compare the names of the color or the
values for unnamed colors.

For example:

Dim color1 As Color = Color.Black
Dim color2 As Color = Color.FromArgb( 0,0,0)

Both are visibly Black, however they are not logically the same value. In
other words:

If color1.Equals(c olor2) Then
' color1 is the same named color as color2
End If

If color1.ToArgb() = color2.ToArgb() Then
' color1 & color2 have the same Alpha, Red, Green & Blue values
End If

Just a thought
Jay
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:ul******** ******@TK2MSFTN GP11.phx.gbl... Dennis,

As alternative
If mycolor.ToArgb = mycolor.Empty.T oArgb

End if

Cor

"Dennis" <De****@discuss ions.microsoft. com>:

public mycolor as color = color.Empty

I want to check to see if the user has specified a color like;

if mycolor = Color.Empty then.....
or
if mycolor is Color.Empty then .......

I get errors saying that = can be used for colors and is can't be used
with
value types. I give up...how do I do this. Thanks.
--
Dennis in Houston


Nov 21 '05 #7
Jay,

It was just an alternative, this one is not real very important for me,
however I like more evaluating for equality using the = operator than
evaluating using a methode and with the color that is possible.

But the "Is" in this functions tells it very good, therefore it is not
really that important for me.

However as I said, just an alternative.

Cor

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com>
Cor (& Herfried),
As I stated in my initial reply:
See the Color.Equals function in the online help for some important
remarks about using Color.Equals and when you may want to use
Color.ToArgb to compare two colors.


If I want to compare what is visible seen I will use Color.ToArgb in other
words to compare the Alpha, Red, Green & Blue values.

If I want to compare what is literally used I will use Color.Equals or
Color.op_Equali ty, in other words to compare the names of the color or the
values for unnamed colors.

For example:

Dim color1 As Color = Color.Black
Dim color2 As Color = Color.FromArgb( 0,0,0)

Both are visibly Black, however they are not logically the same value. In
other words:

If color1.Equals(c olor2) Then
' color1 is the same named color as color2
End If

If color1.ToArgb() = color2.ToArgb() Then
' color1 & color2 have the same Alpha, Red, Green & Blue values
End If

Just a thought
Jay
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:ul******** ******@TK2MSFTN GP11.phx.gbl...
Dennis,

As alternative
If mycolor.ToArgb = mycolor.Empty.T oArgb

End if

Cor

"Dennis" <De****@discuss ions.microsoft. com>:

public mycolor as color = color.Empty

I want to check to see if the user has specified a color like;

if mycolor = Color.Empty then.....
or
if mycolor is Color.Empty then .......

I get errors saying that = can be used for colors and is can't be used
with
value types. I give up...how do I do this. Thanks.
--
Dennis in Houston



Nov 21 '05 #8
Cor,
It was just an alternative, this one is not real very important for me,
Obviously I know its an alternative, Hopefully you noticed that I stated
last night it was an alternative & again just now.

Thanks for noticing.
Jay

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. Jay,

It was just an alternative, this one is not real very important for me,
however I like more evaluating for equality using the = operator than
evaluating using a methode and with the color that is possible.

But the "Is" in this functions tells it very good, therefore it is not
really that important for me.

However as I said, just an alternative.

Cor

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com>
Cor (& Herfried),
As I stated in my initial reply:
See the Color.Equals function in the online help for some important
remarks about using Color.Equals and when you may want to use
Color.ToArgb to compare two colors.


If I want to compare what is visible seen I will use Color.ToArgb in
other words to compare the Alpha, Red, Green & Blue values.

If I want to compare what is literally used I will use Color.Equals or
Color.op_Equali ty, in other words to compare the names of the color or
the values for unnamed colors.

For example:

Dim color1 As Color = Color.Black
Dim color2 As Color = Color.FromArgb( 0,0,0)

Both are visibly Black, however they are not logically the same value. In
other words:

If color1.Equals(c olor2) Then
' color1 is the same named color as color2
End If

If color1.ToArgb() = color2.ToArgb() Then
' color1 & color2 have the same Alpha, Red, Green & Blue values
End If

Just a thought
Jay
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:ul******** ******@TK2MSFTN GP11.phx.gbl...
Dennis,

As alternative
If mycolor.ToArgb = mycolor.Empty.T oArgb

End if

Cor

"Dennis" <De****@discuss ions.microsoft. com>:

public mycolor as color = color.Empty

I want to check to see if the user has specified a color like;

if mycolor = Color.Empty then.....
or
if mycolor is Color.Empty then .......

I get errors saying that = can be used for colors and is can't be used
with
value types. I give up...how do I do this. Thanks.
--
Dennis in Houston



Nov 21 '05 #9
Jay,

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> schrieb:
For example:

Dim color1 As Color = Color.Black
Dim color2 As Color = Color.FromArgb( 0,0,0)

Both are visibly Black, however they are not logically the same value. In
other words:

If color1.Equals(c olor2) Then
' color1 is the same named color as color2
End If

If color1.ToArgb() = color2.ToArgb() Then
' color1 & color2 have the same Alpha, Red, Green & Blue values
End If


That's a valid point, and the way to go depends on the situation.

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

Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
26698
by: Andreas Palm | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as empty elements in the XML. How to do that ? I don't understand why there is no simple option to specify the output format, or did I miss something ? regards andreas
8
10409
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have is not much help here either. Googling has given me a little help. This is my current understanding -- I would appreciate any comments or corrections... "" -- this means an empty string when applied to String data type, and also to Variant...
5
2244
by: Bob Gregory | last post by:
Hi all, I'm utter C# newbie, do be gentle. VS2005 Express refuses point blank to install on my box, so I'm stuck with C# 1.0 unless someone can point me to a C#2.0 compiler elsewhere. I have an authentication system rigged up, which is working, but I'd like to be able to run a test like this <code>
5
2214
by: ma740988 | last post by:
There's a need for me to move around at specified offsets within memory. As as a result - long story short - unsigned char* is the type of choice. At issue: Consider the case ( test code ) where I'm comparing two structs. The struct test1 has information with regards to data_size and pointer to address. The struct test2 has information with regards to data_size and value. I will compare test1 and test2. For each matching data size,...
9
2064
by: Phoe6 | last post by:
Hi, Following are my files. In the format: Filename ---- content ---- config1.txt
7
34844
by: kumar.senthil | last post by:
Hi, I'm using XmlSerializer to create an object from the XML string. I would like to know whether I can get a null value for an empty XML element. Actually the XmlSerializer assigns "" (empty string) for a string if the corresponding element is missing in the XML. Input XML: <DemoClass><A>some value</A><B></B><DemoClass>
12
6850
by: John Smith | last post by:
This code for the comparison of fp types is taken from the C FAQ. Any problems using it in a macro? /* compare 2 doubles for equality */ #define DBL_ISEQUAL(a,b) (fabs((a)-(b))<=(DBL_EPSILON)*fabs((a))) Do the same issues involved in comparing 2 fp types for equality apply to comparing a float to zero? E.g. is if(x == 0.0) considered harmful?
2
3388
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function checkInteger(&$value, $checks) { $err = ''; if (!is_numeric($value) || (floatval($value) != intval($value))) { $err .= 'Input must be an integer. ';
25
13034
by: J Caesar | last post by:
In C you can compare two pointers, p<q, as long as they come from the same array or the same malloc()ated block. Otherwise you can't. What I'd like to do is write a function int comparable(void *p, void *q) that will take any two pointers and decide whether they can be compared or not. I really can't think how to do this - any suggestions?
0
9289
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9158
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9060
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6615
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5939
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4712
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3151
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2508
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.