When to use ( )

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

    #1

    When to use ( )

    In code, I "appear" to see contradictions. ..

    Dim aButton as New Button()

    as well as

    Dim aButton as New Button

    Why are the ( ) present in one case, but not the other ?




  • rowe_newsgroups

    #2
    Re: When to use ( )

    On May 11, 8:59 am, "Rob" <r...@yahoo.com wrote:
    In code, I "appear" to see contradictions. ..
    >
    Dim aButton as New Button()
    >
    as well as
    >
    Dim aButton as New Button
    >
    Why are the ( ) present in one case, but not the other ?
    Visual Basic does not enforce strict parentheses rules like other
    languages such as C# or C++. If they are absent but required the
    compiler will add them for you.

    Thanks,

    Seth Rowe

    Comment

    • Rob

      #3
      Re: When to use ( )

      Thanks...

      However... I would like to know the underlying rule... when does the
      complier require that they be present ?

      Do certain circumstances dictate their presence ?


      "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
      news:1178888440 .922600.52230@w 5g2000hsg.googl egroups.com...
      On May 11, 8:59 am, "Rob" <r...@yahoo.com wrote:
      >In code, I "appear" to see contradictions. ..
      >>
      >Dim aButton as New Button()
      >>
      >as well as
      >>
      >Dim aButton as New Button
      >>
      >Why are the ( ) present in one case, but not the other ?
      >
      Visual Basic does not enforce strict parentheses rules like other
      languages such as C# or C++. If they are absent but required the
      compiler will add them for you.
      >
      Thanks,
      >
      Seth Rowe
      >

      Comment

      • rowe_newsgroups

        #4
        Re: When to use ( )

        On May 11, 9:21 am, "Rob" <r...@yahoo.com wrote:
        Thanks...
        >
        However... I would like to know the underlying rule... when does the
        complier require that they be present ?
        >
        Do certain circumstances dictate their presence ?
        >
        "rowe_newsgroup s" <rowe_em...@yah oo.comwrote in message
        >
        news:1178888440 .922600.52230@w 5g2000hsg.googl egroups.com...
        >
        On May 11, 8:59 am, "Rob" <r...@yahoo.com wrote:
        In code, I "appear" to see contradictions. ..
        >
        Dim aButton as New Button()
        >
        as well as
        >
        Dim aButton as New Button
        >
        Why are the ( ) present in one case, but not the other ?
        >
        Visual Basic does not enforce strict parentheses rules like other
        languages such as C# or C++. If they are absent but required the
        compiler will add them for you.
        >
        Thanks,
        >
        Seth Rowe
        Any time you call a method the parentheses are required - this
        includes object instantiation.

        Thanks,

        Seth Rowe

        Comment

        • diAb0Lo

          #5
          Re: When to use ( )

          On 11 mayo, 08:59, "Rob" <r...@yahoo.com wrote:
          In code, I "appear" to see contradictions. ..
          >
          Dim aButton as New Button()
          >
          as well as
          >
          Dim aButton as New Button
          >
          Why are the ( ) present in one case, but not the other ?
          Hi,

          You must use () with the NEW reserved keyword when the constructor you
          are calling requires one or more parameters. For example:

          Dim myString As New String("AAA")

          It sets myString = "AAA".

          Cheers

          Comment

          • =?Utf-8?B?RGF2aWQgQW50b24=?=

            #6
            Re: When to use ( )

            Actually, VB does not add them for instantiation via parameterless
            constructors (i.e., "x = New Foo" is left as is), but VB does add them for
            paremeterless method calls. I'm not sure for the reason behind this
            inconsistency.
            --
            David Anton
            Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

            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


            "rowe_newsgroup s" wrote:
            On May 11, 9:21 am, "Rob" <r...@yahoo.com wrote:
            Thanks...

            However... I would like to know the underlying rule... when does the
            complier require that they be present ?

            Do certain circumstances dictate their presence ?

            "rowe_newsgroup s" <rowe_em...@yah oo.comwrote in message

            news:1178888440 .922600.52230@w 5g2000hsg.googl egroups.com...
            On May 11, 8:59 am, "Rob" <r...@yahoo.com wrote:
            >In code, I "appear" to see contradictions. ..
            >Dim aButton as New Button()
            >as well as
            >Dim aButton as New Button
            >Why are the ( ) present in one case, but not the other ?
            Visual Basic does not enforce strict parentheses rules like other
            languages such as C# or C++. If they are absent but required the
            compiler will add them for you.
            Thanks,
            Seth Rowe
            >
            Any time you call a method the parentheses are required - this
            includes object instantiation.
            >
            Thanks,
            >
            Seth Rowe
            >
            >

            Comment

            • Mattias Sjögren

              #7
              Re: When to use ( )

              >Actually, VB does not add them for instantiation via parameterless
              >constructors (i.e., "x = New Foo" is left as is), but VB does add them for
              >paremeterles s method calls. I'm not sure for the reason behind this
              >inconsistenc y.
              Maybe because in an instantiation context you could confuse it for an
              array (if you don't remember that curly braces are required)?


              Mattias

              --
              Mattias Sjögren [C# MVP] mattias @ mvps.org
              http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
              Please reply only to the newsgroup.

              Comment

              • Jay B. Harlow [MVP - Outlook]

                #8
                Re: When to use ( )

                Rob,
                In addition to the other comments.

                They are allowed here as they are optional.

                They are optional to avoid the problem of deleting new from your first
                expression & winding up with an array:

                Dim aButton as Button()

                aButton is now an array of buttons, probably not what you intended.

                --
                Hope this helps
                Jay B. Harlow [MVP - Outlook]
                ..NET Application Architect, Enthusiast, & Evangelist
                T.S. Bradley - http://www.tsbradley.net


                "Rob" <robc1@yahoo.co mwrote in message
                news:Ss-dnZpTl-Oi9dnbnZ2dnUVZ_ r-onZ2d@comcast.c om...
                In code, I "appear" to see contradictions. ..
                >
                Dim aButton as New Button()
                >
                as well as
                >
                Dim aButton as New Button
                >
                Why are the ( ) present in one case, but not the other ?
                >
                >
                >
                >

                Comment

                Working...