Help - Array = Nothing - How do I catch

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

    Help - Array = Nothing - How do I catch

    I have a function that returns an array of string values, occasionally
    the returned array value is 'Nothing'
    I need to check if the value is nothing before moving on - how can I do
    this - none of the options i've looked at seems to fit? (vb2005)

    Thanks

    Pete

  • Stephany Young

    #2
    Re: Help - Array = Nothing - How do I catch

    Ummmmm ... How about:

    variable Is Nothing


    "xla76" <pete.forman@gm ail.comwrote in message
    news:1169382080 .704780.283910@ 38g2000cwa.goog legroups.com...
    >I have a function that returns an array of string values, occasionally
    the returned array value is 'Nothing'
    I need to check if the value is nothing before moving on - how can I do
    this - none of the options i've looked at seems to fit? (vb2005)
    >
    Thanks
    >
    Pete
    >

    Comment

    • xla76

      #3
      Re: Help - Array = Nothing - How do I catch

      Doh!

      Thanks


      Stephany Young wrote:
      Ummmmm ... How about:
      >
      variable Is Nothing

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Help - Array = Nothing - How do I catch

        "xla76" <pete.forman@gm ail.comschrieb:
        >I have a function that returns an array of string values, occasionally
        the returned array value is 'Nothing'
        \\\
        If s(n) IsNot Nothing Then
        ...
        End If
        ///

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

        Comment

        • Fabio

          #5
          Re: Help - Array = Nothing - How do I catch

          "xla76" <pete.forman@gm ail.comha scritto nel messaggio
          news:1169383211 .230420.313440@ s34g2000cwa.goo glegroups.com.. .
          Doh!
          >
          Thanks
          >
          >
          Stephany Young wrote:
          >
          >Ummmmm ... How about:
          >>
          > variable Is Nothing
          Nothe that is a bad practice returning nothing for an array or a collection.
          If the code is your you'd better return an empty array or a collection with
          0 elements.

          --



          Comment

          • Armin Zingler

            #6
            Re: Help - Array = Nothing - How do I catch

            "Fabio" <znt.fabio@virg ilio.itschrieb
            >
            Nothe that is a bad practice returning nothing for an array or a
            collection. If the code is your you'd better return an empty array
            or a collection with 0 elements.

            If there is nothing to return why not return nothing? Sometimes Nothing
            expresses something different from an empty array. I think it depends on the
            purpose of the function whether it makes sense to return Nothing.


            Armin

            Comment

            • Cor Ligthert [MVP]

              #7
              Re: Help - Array = Nothing - How do I catch

              Armin,

              I was in doubt if I would write something about this. Now you do it, it is
              easy to write that I agree with you. Just to show my opinion in this. In
              this case was showing nothing bad.

              Cor

              "Armin Zingler" <az.nospam@free net.deschreef in bericht
              news:%23CCA6WaP HHA.1756@TK2MSF TNGP05.phx.gbl. ..
              "Fabio" <znt.fabio@virg ilio.itschrieb
              >>
              >Nothe that is a bad practice returning nothing for an array or a
              >collection. If the code is your you'd better return an empty array
              >or a collection with 0 elements.
              >
              >
              If there is nothing to return why not return nothing? Sometimes Nothing
              expresses something different from an empty array. I think it depends on
              the
              purpose of the function whether it makes sense to return Nothing.
              >
              >
              Armin
              >

              Comment

              • Master Programmer

                #8
                Re: Help - Array = Nothing - How do I catch

                Dim Arr As Array

                If Arr.GetLength= 0 then


                The Grand Master


                xla76 wrote:
                I have a function that returns an array of string values, occasionally
                the returned array value is 'Nothing'
                I need to check if the value is nothing before moving on - how can I do
                this - none of the options i've looked at seems to fit? (vb2005)
                >
                Thanks
                >
                Pete

                Comment

                • Fabio Z

                  #9
                  Re: Help - Array = Nothing - How do I catch

                  "Armin Zingler" <az.nospam@free net.deha scritto nel messaggio
                  news:%23CCA6WaP HHA.1756@TK2MSF TNGP05.phx.gbl. ..

                  >Nothe that is a bad practice returning nothing for an array or a
                  >collection. If the code is your you'd better return an empty array
                  >or a collection with 0 elements.
                  >
                  >
                  If there is nothing to return why not return nothing? Sometimes Nothing
                  expresses something different from an empty array. I think it depends on
                  the
                  purpose of the function whether it makes sense to return Nothing.
                  Simply because it is ambiguos for the developer that will use that code.
                  He won't know if the function will return something or not and force him to
                  overkill code to test useless condition such as

                  If Not array Is Nothing Then
                  If array.Lenght 0 Then
                  Else
                  ' error
                  Endif
                  Else
                  ' error
                  Endif

                  resulting in less readable code, less performances and so on, and if Him
                  forget/don't know that the array can be nothing the app will crash.

                  This is the same reason for that someone suggest to not return nothing for a
                  derived class in a factory pattern but an istance of MyInvalidClass.

                  But everyone can choose its way to be "not CLS compliant" :)


                  Comment

                  • Armin Zingler

                    #10
                    Re: Help - Array = Nothing - How do I catch

                    "Fabio Z" <znt.fabio@virg ilio.itschrieb
                    "Armin Zingler" <az.nospam@free net.deha scritto nel messaggio
                    news:%23CCA6WaP HHA.1756@TK2MSF TNGP05.phx.gbl. ..
                    >
                    >
                    Nothe that is a bad practice returning nothing for an array or a
                    collection. If the code is your you'd better return an empty
                    array or a collection with 0 elements.

                    If there is nothing to return why not return nothing? Sometimes
                    Nothing expresses something different from an empty array. I think
                    it depends on the
                    purpose of the function whether it makes sense to return Nothing.
                    >
                    Simply because it is ambiguos for the developer that will use that
                    code. He won't know if the function will return something or not
                    If he doesn't know he should read the function's documentation.

                    "If the file is not found, the return value is Nothing. Otherwise it returns
                    an array containing one item per entry within the file. There might be zero
                    items in the file." (just an example)

                    BTW, zero <DBNull.Value .
                    and
                    force him to overkill code to test useless condition such as
                    >
                    If Not array Is Nothing Then
                    If array.Lenght 0 Then
                    Else
                    ' error
                    Endif
                    Else
                    ' error
                    Endif
                    >
                    resulting in less readable code, less performances and so on,
                    I think it is not less readable. The code handles all possible situations.
                    and if
                    Him forget/don't know that the array can be nothing the app will
                    crash.
                    see 1st paragraph
                    This is the same reason for that someone suggest to not return
                    nothing for a derived class in a factory pattern but an istance of
                    MyInvalidClass.
                    >
                    But everyone can choose its way to be "not CLS compliant" :)
                    Not a CLS issue, I think.


                    Armin

                    Comment

                    • Fabio Z

                      #11
                      Re: Help - Array = Nothing - How do I catch

                      "Armin Zingler" <az.nospam@free net.deha scritto nel messaggio
                      If he doesn't know he should read the function's documentation.
                      If you wrote it.

                      "If the file is not found, the return value is Nothing.
                      Boolean?

                      Otherwise it returns an array containing one item per entry within the
                      file. There might be zero items in the file." (just an example)
                      ???
                      I don't understand the example.

                      BTW, zero <DBNull.Value .
                      ???
                      from where DBNull.Value comes now?
                      DBNull.Value is a special class (As I sayd in previous post) used instead of
                      Nothing to indicate a non valid value.


                      >
                      Not a CLS issue, I think.
                      Yes, just a common sense issue.
                      I would say "everyone can choose its way to write bad code".


                      Comment

                      • Armin Zingler

                        #12
                        Re: Help - Array = Nothing - How do I catch

                        "Fabio Z" <znt.fabio@virg ilio.itschrieb
                        "Armin Zingler" <az.nospam@free net.deha scritto nel messaggio
                        >
                        If he doesn't know he should read the function's documentation.
                        >
                        If you wrote it.
                        And if you use it. If you don't know what you use, you shouldn't.
                        "If the file is not found, the return value is Nothing.
                        >
                        Boolean?
                        "As String()"?

                        I think I see what you mean but this would require another argument. Both is
                        valid.
                        Otherwise it returns an array containing one item per entry within
                        the file. There might be zero items in the file." (just an
                        example)
                        >
                        ???
                        I don't understand the example.
                        It shows that Nothing and an empty array is not the same. Nothing can
                        express something different than an empty array. The documentation clearly
                        states when is returned what.
                        BTW, zero <DBNull.Value .
                        >
                        ???
                        from where DBNull.Value comes now?
                        DBNull.Value is a special class (As I sayd in previous post) used
                        instead of Nothing to indicate a non valid value.
                        I wanted to show that zero is not the same as DBNull.Value just like Nothing
                        is not the same as an empty array.

                        Not a CLS issue, I think.
                        >
                        Yes, just a common sense issue.
                        I would say "everyone can choose its way to write bad code".
                        Umm.... yes.


                        Armin

                        Comment

                        • Fabio

                          #13
                          Re: Help - Array = Nothing - How do I catch

                          "Armin Zingler" <az.nospam@free net.deha scritto nel messaggio
                          news:eCR6PEkPHH A.420@TK2MSFTNG P06.phx.gbl...

                          If he doesn't know he should read the function's documentation.
                          >>
                          >If you wrote it.
                          >
                          And if you use it. If you don't know what you use, you shouldn't.
                          Ok, you're right.
                          "If you don't know what you use, you shouldn't"




                          Comment

                          Working...