Help required with simple syntax error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ceasar

    Help required with simple syntax error

    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.

  • Tom Dacon

    #2
    Re: Help required with simple syntax error

    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

    "ceasar" <~~> wrote in message news:eum12VsxEH A.2192@TK2MSFTN GP14.phx.gbl...[color=blue]
    > 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]


    Comment

    • ceasar

      #3
      Re: Help required with simple syntax error

      Many thanks, you have solved the problem :))

      Comment

      • Arne Janning

        #4
        Re: Help required with simple syntax error

        Ave Caesar,

        "ceasar" schrieb[color=blue]
        > 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'.[/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_Equali ty(TreeView1.No des(0).ForeColo r, Color.OldLace)

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

        Cheers

        Arne Janning


        Comment

        • Cor Ligthert

          #5
          Re: Help required with simple syntax error

          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

          "Arne Janning" <spam.me-here.arnolo@msn .com>[color=blue]
          > Ave Caesar,
          >
          > "ceasar" schrieb[color=green]
          >> 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'.[/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_Equali ty(TreeView1.No des(0).ForeColo r, Color.OldLace)
          >
          > If retVal = True Then
          > MsgBox("Yo")
          > End If
          >
          > Cheers
          >
          > Arne Janning
          >[/color]


          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Help required with simple syntax error

            "Arne Janning" <spam.me-here.arnolo@msn .com> schrieb:[color=blue][color=green]
            >> 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'.[/color][/color]

            VB.NET does not support overloading the equality operator, and 'Color' is a
            value type, thus 'Is' and '=' cannot be used in this situation.
            [color=blue]
            > This works:
            >
            > TreeView1.Nodes .Add("Hello World")
            > TreeView1.Nodes (0).ForeColor = Color.OldLace
            >
            > Dim retVal As Boolean
            > retVal = Color.op_Equali ty(TreeView1.No des(0).ForeColo r, Color.OldLace)[/color]

            .... or...

            \\\
            RetVal = TreeView1.Nodes (0).ForeColor.E quals(Color.Old Lace)
            ///

            --
            Herfried K. Wagner [MVP]
            <URL:http://dotnet.mvps.org/>

            Comment

            • Arne Janning

              #7
              Re: Help required with simple syntax error

              Hi Herfried!

              "Herfried K. Wagner [MVP]" schrieb[color=blue]
              > VB.NET does not support overloading the equality operator, and 'Color' is
              > a value type, thus 'Is' and '=' cannot be used in this situation.[/color]

              Thanks for the concise explanation!

              Cheers

              AJ


              Comment

              • Arne Janning

                #8
                Re: Help required with simple syntax error

                Hi Herfried!

                "Herfried K. Wagner [MVP]" schrieb[color=blue]
                > VB.NET does not support overloading the equality operator, and 'Color' is
                > a value type, thus 'Is' and '=' cannot be used in this situation.[/color]

                Thanks for the concise explanation!

                Cheers

                AJ


                Comment

                Working...