Overloading of the unary ++ operator in VB.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?VkIgRGV2ZWxvcGVy?=

    Overloading of the unary ++ operator in VB.net

    Overloading of the unary ++ operator in vb.net is not working. It show error:
    Operator declaration must be one of: +, -, *, \, /, ^, &, Like, Mod, And,
    Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType, IsTrue, IsFalse.

    Is there any way can to get rid of this error?

    C# is working fine for overloading ++, and do I need to change developing
    language to C#? Any suggestion?
  • Tom Shelton

    #2
    Re: Overloading of the unary ++ operator in VB.net

    On 2008-04-29, VB Developer <VBDeveloper@di scussions.micro soft.comwrote:
    Overloading of the unary ++ operator in vb.net is not working. It show error:
    Operator declaration must be one of: +, -, *, \, /, ^, &, Like, Mod, And,
    Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType, IsTrue, IsFalse.
    >
    Is there any way can to get rid of this error?
    >
    C# is working fine for overloading ++, and do I need to change developing
    language to C#? Any suggestion?
    ++ is not an operator in VB.NET. As the error says, it must be one of
    the listed operators.

    --
    Tom Shelton

    Comment

    • Armin Zingler

      #3
      Re: Overloading of the unary ++ operator in VB.net

      "VB Developer" <VBDeveloper@di scussions.micro soft.comschrieb
      Overloading of the unary ++ operator in vb.net is not working. It
      show error: Operator declaration must be one of: +, -, *, \, /, ^,
      &, Like, Mod, And, Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType,
      IsTrue, IsFalse.
      >
      Is there any way can to get rid of this error?
      Yes, don't use "++". "++" is not a valid operator; but not only with
      overloading. It does not exist.
      C# is working fine for overloading ++, and do I need to change
      developing language to C#?
      You can't. You are VB Developer.


      Armin

      Comment

      • Andrew Morton

        #4
        Re: Overloading of the unary ++ operator in VB.net

        Tom Shelton wrote:
        On 2008-04-29, VB Developer <VBDeveloper@di scussions.micro soft.com>
        wrote:
        >Overloading of the unary ++ operator in vb.net is not working. It
        >show error: Operator declaration must be one of: +, -, *, \, /, ^,
        >&, Like, Mod, And, Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType,
        >IsTrue, IsFalse.
        >>
        >Is there any way can to get rid of this error?
        >>
        >C# is working fine for overloading ++, and do I need to change
        >developing language to C#? Any suggestion?
        >
        ++ is not an operator in VB.NET. As the error says, it must be one of
        the listed operators.
        Or one of +=, *=, &= and so on, which the help/error message seems to miss
        out.

        Andrew


        Comment

        • Tom Shelton

          #5
          Re: Overloading of the unary ++ operator in VB.net

          On 2008-04-29, Andrew Morton <akm@in-press.co.uk.inv alidwrote:
          Tom Shelton wrote:
          >On 2008-04-29, VB Developer <VBDeveloper@di scussions.micro soft.com>
          >wrote:
          >>Overloading of the unary ++ operator in vb.net is not working. It
          >>show error: Operator declaration must be one of: +, -, *, \, /, ^,
          >>&, Like, Mod, And, Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType,
          >>IsTrue, IsFalse.
          >>>
          >>Is there any way can to get rid of this error?
          >>>
          >>C# is working fine for overloading ++, and do I need to change
          >>developing language to C#? Any suggestion?
          >>
          >++ is not an operator in VB.NET. As the error says, it must be one of
          >the listed operators.
          >
          Or one of +=, *=, &= and so on, which the help/error message seems to miss
          out.
          >
          Andrew
          hmmm, you are correct :) It does seem to leave those out.

          --
          Tom Shelton

          Comment

          • Patrice

            #6
            Re: Overloading of the unary ++ operator in VB.net

            "Andrew Morton" <akm@in-press.co.uk.inv alida écrit dans le message de
            groupe de discussion : 67oq4tF2prk2kU1 @mid.individual .net...
            Tom Shelton wrote:
            >On 2008-04-29, VB Developer <VBDeveloper@di scussions.micro soft.com>
            >wrote:
            >>Overloading of the unary ++ operator in vb.net is not working. It
            >>show error: Operator declaration must be one of: +, -, *, \, /, ^,
            >>&, Like, Mod, And, Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType,
            >>IsTrue, IsFalse.
            >>>
            >>Is there any way can to get rid of this error?
            >>>
            >>C# is working fine for overloading ++, and do I need to change
            >>developing language to C#? Any suggestion?
            >>
            >++ is not an operator in VB.NET. As the error says, it must be one of
            >the listed operators.
            >
            Or one of +=, *=, &= and so on, which the help/error message seems to
            miss out.
            >
            Andrew
            >
            Similarly I would say that += etc... doesn't really exists. This is just a
            shortcut notation... What if you try just + or whatever fit your needs ?

            You may want to explain what you are trying to do...
            --
            Patrice



            Comment

            • =?Utf-8?B?VkIgRGV2ZWxvcGVy?=

              #7
              Re: Overloading of the unary ++ operator in VB.net

              += is not work too.

              Code:
              Public Shared Operator +=(ByVal bi As Integer) As Integer
              ............... .....

              End Operator

              Give the same error above.

              Please check it before post yours.




              "Tom Shelton" wrote:
              On 2008-04-29, Andrew Morton <akm@in-press.co.uk.inv alidwrote:
              Tom Shelton wrote:
              On 2008-04-29, VB Developer <VBDeveloper@di scussions.micro soft.com>
              wrote:
              >Overloading of the unary ++ operator in vb.net is not working. It
              >show error: Operator declaration must be one of: +, -, *, \, /, ^,
              >&, Like, Mod, And, Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType,
              >IsTrue, IsFalse.
              >>
              >Is there any way can to get rid of this error?
              >>
              >C# is working fine for overloading ++, and do I need to change
              >developing language to C#? Any suggestion?
              >
              ++ is not an operator in VB.NET. As the error says, it must be one of
              the listed operators.
              Or one of +=, *=, &= and so on, which the help/error message seems to miss
              out.

              Andrew
              >
              hmmm, you are correct :) It does seem to leave those out.
              >
              --
              Tom Shelton
              >

              Comment

              • Andrew Morton

                #8
                Re: Overloading of the unary ++ operator in VB.net

                Patrice wrote:
                "Andrew Morton" <akm@a écrit dans le message
                >Or one of +=, *=, &= and so on, which the help/error message seems
                >to miss out.
                >>
                >Andrew
                >>
                >
                Similarly I would say that += etc... doesn't really exists. This is
                just a shortcut notation... What if you try just + or whatever fit
                your needs ?
                You may want to explain what you are trying to do...
                /I/'m trying to let the OP know there's no ++ operator in VB.NET... :-)

                Andrew


                Comment

                • Tom Shelton

                  #9
                  Re: Overloading of the unary ++ operator in VB.net

                  On 2008-04-29, VB Developer <VBDeveloper@di scussions.micro soft.comwrote:
                  += is not work too.
                  >
                  Code:
                  Public Shared Operator +=(ByVal bi As Integer) As Integer
                  ............... ....
                  >
                  End Operator
                  >
                  Give the same error above.
                  >
                  Please check it before post yours.
                  >
                  >
                  Actually, looking in the docs, +=, -=, etc are not valid for
                  overloading, so the error message is perfectly correct. You would have
                  to overload the +:

                  Public Shared Operator +(ByVal bi As Integer) As Integer
                  End Sub

                  += and friends are compiler shortcuts - not actual operators.


                  --
                  Tom Shelton

                  Comment

                  • Armin Zingler

                    #10
                    Re: Overloading of the unary ++ operator in VB.net

                    "VB Developer" <VBDeveloper@di scussions.micro soft.comschrieb
                    += is not work too.
                    >
                    Code:
                    Public Shared Operator +=(ByVal bi As Integer) As Integer
                    ............... ....
                    >
                    End Operator
                    >
                    Give the same error above.
                    >
                    Please check it before post yours.
                    See Patrice' reply. The "real" operator is "+". You will be able to use
                    "dest += value" just like "dest = dest + value"


                    Armin

                    Comment

                    • =?Utf-8?B?VkIgRGV2ZWxvcGVy?=

                      #11
                      Re: Overloading of the unary ++ operator in VB.net


                      I want to transfer C# code to VB.net code. I know now it is impossible at
                      some part and except you change original code such as ++ to +1.



                      "Patrice" wrote:
                      "Andrew Morton" <akm@in-press.co.uk.inv alida écrit dans le message de
                      groupe de discussion : 67oq4tF2prk2kU1 @mid.individual .net...
                      Tom Shelton wrote:
                      On 2008-04-29, VB Developer <VBDeveloper@di scussions.micro soft.com>
                      wrote:
                      >Overloading of the unary ++ operator in vb.net is not working. It
                      >show error: Operator declaration must be one of: +, -, *, \, /, ^,
                      >&, Like, Mod, And, Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType,
                      >IsTrue, IsFalse.
                      >>
                      >Is there any way can to get rid of this error?
                      >>
                      >C# is working fine for overloading ++, and do I need to change
                      >developing language to C#? Any suggestion?
                      >
                      ++ is not an operator in VB.NET. As the error says, it must be one of
                      the listed operators.
                      Or one of +=, *=, &= and so on, which the help/error message seems to
                      miss out.

                      Andrew
                      >
                      Similarly I would say that += etc... doesn't really exists. This is just a
                      shortcut notation... What if you try just + or whatever fit your needs ?
                      >
                      You may want to explain what you are trying to do...
                      --
                      Patrice
                      >
                      >
                      >
                      >

                      Comment

                      • Patrice

                        #12
                        Re: Overloading of the unary ++ operator in VB.net

                        This is just to port code and an attempt to avoid changing ++ ?

                        Depending on the reason for this port you could :
                        - compile the C# code into a DLL so that you can reuse this code without
                        even having to port
                        - also I've heard about translators being able to take source code in a
                        particular language and translate it to another language (try googling for
                        this)

                        Of course if you really want to this by hand you'll have anyway much bigger
                        changes than that...
                        --
                        Patrice

                        "VB Developer" <VBDeveloper@di scussions.micro soft.coma écrit dans le
                        message de groupe de discussion :
                        DDC5A314-5342-4646-93D0-02852962E806@mi crosoft.com...
                        >
                        I want to transfer C# code to VB.net code. I know now it is impossible at
                        some part and except you change original code such as ++ to +1.


                        Comment

                        • Tom Shelton

                          #13
                          Re: Overloading of the unary ++ operator in VB.net

                          On 2008-04-29, VB Developer <VBDeveloper@di scussions.micro soft.comwrote:
                          >
                          I want to transfer C# code to VB.net code. I know now it is impossible at
                          some part and except you change original code such as ++ to +1.
                          >
                          >
                          >
                          Yep. VB.NET doesn't support pre/post increment/decrement operators.
                          The closest you get is:

                          b += 1

                          or

                          b -= 1

                          And that is just a shortcut for:

                          b = b + 1

                          or

                          b = b -1

                          One more reson to prefer C# :)

                          --
                          Tom Shelton

                          Comment

                          • Herfried K. Wagner [MVP]

                            #14
                            Re: Overloading of the unary ++ operator in VB.net

                            "VB Developer" <VBDeveloper@di scussions.micro soft.comschrieb :
                            Overloading of the unary ++ operator in vb.net is not working. It show
                            error:
                            Operator declaration must be one of: +, -, *, \, /, ^, &, Like, Mod, And,
                            Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType, IsTrue, IsFalse.
                            >
                            Is there any way can to get rid of this error?
                            Overload the '+' operator. You may want to handle the case of
                            incrementation "by one" differently.
                            C# is working fine for overloading ++, and do I need to change developing
                            language to C#? Any suggestion?
                            Why would you want to overload this operator? Note that this operator is
                            syntactic sugar, as is '+='. VB does not even support the '++' shorthand
                            syntax.

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

                            Comment

                            • Herfried K. Wagner [MVP]

                              #15
                              Re: Overloading of the unary ++ operator in VB.net

                              "Tom Shelton" <tom_shelton@YO UKNOWTHEDRILLco mcast.netschrie b:
                              >I want to transfer C# code to VB.net code. I know now it is impossible
                              >at
                              >some part and except you change original code such as ++ to +1.
                              >>
                              >>
                              >>
                              >
                              Yep. VB.NET doesn't support pre/post increment/decrement operators.
                              The closest you get is:
                              >
                              b += 1
                              >
                              or
                              >
                              b -= 1
                              >
                              And that is just a shortcut for:
                              >
                              b = b + 1
                              >
                              or
                              >
                              b = b -1
                              >
                              One more reson to prefer C# :)
                              Well, opinions seem to differ. I don't see any reason for an additional way
                              to achieve a certain thing which only saves a few keystrokes but requires
                              additional keystrokes if incrementation/decrementation should be changed
                              from 1 to another value.

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

                              Comment

                              Working...