Help required with simple syntax error

  • Thread starter Thread starter ceasar
  • Start date Start date
C

ceasar

Hello all,
My editor seems to not accept the following:

Dim color As New System.Drawing.Color
If node.ForeColor Is color.Violet Then Exit Sub

Form1.vb(363): 'Is' requires operands that have reference types, but this
operand has the value type 'System.Drawing.Color'.

where node is Treenode (of Treeview)

Thanks.
 
Color is a struct, not a class, so Is doesn't apply. I'd expect that Color's
Equals() method would do the job. Give it a try.

Tom Dacon
Dacon Software Consulting
 
Ave Caesar,

My editor seems to not accept the following:

Dim color As New System.Drawing.Color
If node.ForeColor Is color.Violet Then Exit Sub

Form1.vb(363): 'Is' requires operands that have reference types, but this
operand has the value type 'System.Drawing.Color'.

Dont ask me why this works, just pass the rubikon (Herfried and Cor surely
will explain it to you in detail, they are both educated in ancient history
and therefore know VB-Syntax better than I do ;-)

This works:

TreeView1.Nodes.Add("Hello World")
TreeView1.Nodes(0).ForeColor = Color.OldLace

Dim retVal As Boolean
retVal = Color.op_Equality(TreeView1.Nodes(0).ForeColor, Color.OldLace)

If retVal = True Then
MsgBox("Yo")
End If

Cheers

Arne Janning
 
Arne,

(I do not know what "Ave" is in the old germanic way, however probably
something people would misunderstand so let me not do that)

"Is" is about the reference too an object
"=" is about the contents (value)

You can try this one.
Dim a As DataSet
Dim b As Object
If a Is b Then _
MessageBox.Show("There is no dataset")
a = New DataSet
If Not a Is b Then _
MessageBox.Show("There is a dataset")

An not instanced object Is the same as Nothing

When you set
a = New Dataset, you set the value(address) of the reference from "a" to the
new created dataset because "a" is an object

When you set
dim a as integer = 1 you set the value of "a" too 1 because "a" is a value.

Is it not simple?

Cor
 
VB.NET does not support overloading the equality operator, and 'Color' is a
value type, thus 'Is' and '=' cannot be used in this situation.
This works:

TreeView1.Nodes.Add("Hello World")
TreeView1.Nodes(0).ForeColor = Color.OldLace

Dim retVal As Boolean
retVal = Color.op_Equality(TreeView1.Nodes(0).ForeColor, Color.OldLace)

.... or...

\\\
RetVal = TreeView1.Nodes(0).ForeColor.Equals(Color.OldLace)
///
 
Hi Herfried!

VB.NET does not support overloading the equality operator, and 'Color' is
a value type, thus 'Is' and '=' cannot be used in this situation.

Thanks for the concise explanation!

Cheers

AJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top