Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. I just want to be really really sure

I just want to be really really sure

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharp
14 Posts 10 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A AnalogNerd

    I just found this wonderful tidbit in a .NET app I'm supporting.

    TextBox tbRoute = (TextBox)FindControl("ChkRoute" + cnt.ToString());

    if ((tbRoute.Text != "") && (tbRoute.Text != "") && (tbRoute.Text != "")) {

    ...

    }

    R Offline
    R Offline
    Richard C Bishop
    wrote on last edited by
    #5

    So....what exactly is wrong with that?

    1 Reply Last reply
    0
    • A AnalogNerd

      I just found this wonderful tidbit in a .NET app I'm supporting.

      TextBox tbRoute = (TextBox)FindControl("ChkRoute" + cnt.ToString());

      if ((tbRoute.Text != "") && (tbRoute.Text != "") && (tbRoute.Text != "")) {

      ...

      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #6

      Did you check that the Text property Getter didn't make changes to the underlying data and so make that a valid statement. e.g.

      private string _text;
      public string Text
      {
      Get{
      if (_text == null)
      {
      _text = "Empty";
      return _text;
      }
      if (_text == "Empty")
      _text = "";

      return _text;

      }
      }

      MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')

      A 1 Reply Last reply
      0
      • L Lost User

        Did you check that the Text property Getter didn't make changes to the underlying data and so make that a valid statement. e.g.

        private string _text;
        public string Text
        {
        Get{
        if (_text == null)
        {
        _text = "Empty";
        return _text;
        }
        if (_text == "Empty")
        _text = "";

        return _text;

        }
        }

        MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')

        A Offline
        A Offline
        Argonia
        wrote on last edited by
        #7

        _Maxxx_ wrote:

        if (_text = "Empty") _text = "";

        This will be always be true no matter what _text is :D except for F# but there the if else operation contains then :)

        Microsoft ... the only place where VARIANT_TRUE != true

        L R 2 Replies Last reply
        0
        • A Argonia

          _Maxxx_ wrote:

          if (_text = "Empty") _text = "";

          This will be always be true no matter what _text is :D except for F# but there the if else operation contains then :)

          Microsoft ... the only place where VARIANT_TRUE != true

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #8

          Thanks for the human compiler - I've fixed it.

          MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')

          1 Reply Last reply
          0
          • A AnalogNerd

            I just found this wonderful tidbit in a .NET app I'm supporting.

            TextBox tbRoute = (TextBox)FindControl("ChkRoute" + cnt.ToString());

            if ((tbRoute.Text != "") && (tbRoute.Text != "") && (tbRoute.Text != "")) {

            ...

            }

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #9

            AnalogNerd wrote:

            if ((tbRoute.Text != "") && (tbRoute.Text != "") && (tbRoute.Text != "")) {

            Third time is the charm

            1 Reply Last reply
            0
            • A AnalogNerd

              I just found this wonderful tidbit in a .NET app I'm supporting.

              TextBox tbRoute = (TextBox)FindControl("ChkRoute" + cnt.ToString());

              if ((tbRoute.Text != "") && (tbRoute.Text != "") && (tbRoute.Text != "")) {

              ...

              }

              G Offline
              G Offline
              Gary R Wheeler
              wrote on last edited by
              #10

              I've unintentionally had that happen after some refactoring. A couple text boxes contained values, and were later converted to a single box. Refactoring the name of the second to be the same as the first created the circumstance found here. Of course, that situation only lasted for a little while, since I did check all the references to make sure nothing too stupid happened...

              Software Zen: delete this;

              1 Reply Last reply
              0
              • A Argonia

                _Maxxx_ wrote:

                if (_text = "Empty") _text = "";

                This will be always be true no matter what _text is :D except for F# but there the if else operation contains then :)

                Microsoft ... the only place where VARIANT_TRUE != true

                R Offline
                R Offline
                Robert Rohde
                wrote on last edited by
                #11

                No it won't. It wouldn't compile...

                A 1 Reply Last reply
                0
                • R Robert Rohde

                  No it won't. It wouldn't compile...

                  A Offline
                  A Offline
                  Argonia
                  wrote on last edited by
                  #12

                  It depends on the compiler and the language you are writing in. In c++ it will compile and run and you will be looking for a bug :D

                  Microsoft ... the only place where VARIANT_TRUE != true

                  1 Reply Last reply
                  0
                  • A AnalogNerd

                    I just found this wonderful tidbit in a .NET app I'm supporting.

                    TextBox tbRoute = (TextBox)FindControl("ChkRoute" + cnt.ToString());

                    if ((tbRoute.Text != "") && (tbRoute.Text != "") && (tbRoute.Text != "")) {

                    ...

                    }

                    M Offline
                    M Offline
                    MacSpudster
                    wrote on last edited by
                    #13

                    At least give the guy credit for ensuring that no variable leaves empty-handed.

                    1 Reply Last reply
                    0
                    • A AnalogNerd

                      I just found this wonderful tidbit in a .NET app I'm supporting.

                      TextBox tbRoute = (TextBox)FindControl("ChkRoute" + cnt.ToString());

                      if ((tbRoute.Text != "") && (tbRoute.Text != "") && (tbRoute.Text != "")) {

                      ...

                      }

                      I Offline
                      I Offline
                      ian dennis 0
                      wrote on last edited by
                      #14

                      Somebody knows the "Tell me 3 times and it must be true" rule (see Heinlein's "Number of the Beast")

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups