Dereferencing

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

    Dereferencing

    Hi,

    How would I handle Dereferencing in vb.Net 2003.

    Something like:
    Dim txt As TextBox = DirectCast("txt " & someStringVaria ble, TextBox)

    This sadly won't work because a type of string cannot be casted to a textbox.
    The "txt" + someStringVaria ble concatenation would represent a valid name of a textbox on the form.

    Thanks for any ideas,

    Michael
  • Herfried K. Wagner [MVP]

    #2
    Re: Dereferencing

    * "Michael Maes" <michael@merlot .com> scripsit:[color=blue]
    > How would I handle Dereferencing in vb.Net 2003.
    >
    > Something like:
    >
    > Dim txt As TextBox = DirectCast("txt " & someStringVaria ble, TextBox)[/color]

    Store (name, control) pairs in a 'Hashtable'.

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

    Comment

    • CJ Taylor

      #3
      Re: Dereferencing

      Are you trying to create a textbox control from a string variable as the name? I don't quite understand what your trying to do, but would be curiuos to learn what dereferencing is.

      -CJ
      "Michael Maes" <michael@merlot .com> wrote in message news:e8aLX8j8DH A.2044@TK2MSFTN GP10.phx.gbl...
      Hi,

      How would I handle Dereferencing in vb.Net 2003.

      Something like:
      Dim txt As TextBox = DirectCast("txt " & someStringVaria ble, TextBox)

      This sadly won't work because a type of string cannot be casted to a textbox.
      The "txt" + someStringVaria ble concatenation would represent a valid name of a textbox on the form.

      Thanks for any ideas,

      Michael

      Comment

      • Michael Maes

        #4
        Re: Dereferencing

        Thanks,

        It's a 'workaround' but it will do the job.
        Must I conclude that in VB this is not possible?

        Michael

        "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
        news:uyfueEk8DH A.2952@TK2MSFTN GP09.phx.gbl...
        | * "Michael Maes" <michael@merlot .com> scripsit:
        | > How would I handle Dereferencing in vb.Net 2003.
        | >
        | > Something like:
        | >
        | > Dim txt As TextBox = DirectCast("txt " & someStringVaria ble, TextBox)
        |
        | Store (name, control) pairs in a 'Hashtable'.
        |
        | --
        | Herfried K. Wagner [MVP]
        | <http://www.mvps.org/dotnet>


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Dereferencing

          * "Michael Maes" <michael@merlot .com> scripsit:[color=blue]
          > It's a 'workaround' but it will do the job.
          > Must I conclude that in VB this is not possible?[/color]

          Yes, it's not possible "out of the box".

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

          Comment

          • Michael Maes

            #6
            Re: Dereferencing

            Hi CJ,

            Until a couple of years ago I was a Coldfusion developer (up to v4.5).
            In CFML there was a function 'Evaluate(Expre ssion)'.
            Lets say you have a structure 'Language_Enu' and 'Language_Nl'
            Both would have the same 'member variables', like eg 'SaveAndClose'

            To retreive the value of 'SaveAndClose' you could then set eg a current_languag e_variable cLang (String) scoping the entire application. So you could fetch your var like:

            Evaluate("Langu age_" & #current_langua ge_variable# & ".SaveAndClose" )

            giving you the right value for the right language.

            Since CFML (at that time) wasn't OOP, this only worked for Variables (I think -> long time ago!)

            If I'm right, this type of operation is called Dereferencing.

            Now I'd like to retreive properties of controls having practically the same name. Instead of writing numorous nearly identical lines of code, I thought I could use this principal.

            If this is not possible in vb.Net, I will use Herfrieds' solution and create the Hashtable dynamically by scanning recursively through the forms-controlcollecti on.

            Maybe you have got another idea / approach.

            Kind regards,

            Michael

            "CJ Taylor" <nospam@blowgoa ts.com> wrote in message news:102pp7ri60 79cdc@corp.supe rnews.com...
            Are you trying to create a textbox control from a string variable as the name? I don't quite understand what your trying to do, but would be curiuos to learn what dereferencing is.

            -CJ
            "Michael Maes" <michael@merlot .com> wrote in message news:e8aLX8j8DH A.2044@TK2MSFTN GP10.phx.gbl...
            Hi,

            How would I handle Dereferencing in vb.Net 2003.

            Something like:
            Dim txt As TextBox = DirectCast("txt " & someStringVaria ble, TextBox)

            This sadly won't work because a type of string cannot be casted to a textbox.
            The "txt" + someStringVaria ble concatenation would represent a valid name of a textbox on the form.

            Thanks for any ideas,

            Michael

            Comment

            • Michael Maes

              #7
              Re: Dereferencing

              That's a pitty.
              Maybe we'll see this functionality in Whidbey ?!?

              Thanks Herfried


              "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
              news:OaYVEil8DH A.4060@tk2msftn gp13.phx.gbl...
              | * "Michael Maes" <michael@merlot .com> scripsit:
              | > It's a 'workaround' but it will do the job.
              | > Must I conclude that in VB this is not possible?
              |
              | Yes, it's not possible "out of the box".
              |
              | --
              | Herfried K. Wagner [MVP]
              | <http://www.mvps.org/dotnet>


              Comment

              • CJ Taylor

                #8
                Re: Dereferencing

                I gotcha... Same thing could be done in JavaScript with the eval statement I believe... I remember doing something like this a couple times, just didn't know it was called derefrencing. Thanks for the pointer though!

                -CJ
                "Michael Maes" <michael@merlot .com> wrote in message news:OH5r4kl8DH A.2608@TK2MSFTN GP10.phx.gbl...
                Hi CJ,

                Until a couple of years ago I was a Coldfusion developer (up to v4.5).
                In CFML there was a function 'Evaluate(Expre ssion)'.
                Lets say you have a structure 'Language_Enu' and 'Language_Nl'
                Both would have the same 'member variables', like eg 'SaveAndClose'

                To retreive the value of 'SaveAndClose' you could then set eg a current_languag e_variable cLang (String) scoping the entire application. So you could fetch your var like:

                Evaluate("Langu age_" & #current_langua ge_variable# & ".SaveAndClose" )

                giving you the right value for the right language.

                Since CFML (at that time) wasn't OOP, this only worked for Variables (I think -> long time ago!)

                If I'm right, this type of operation is called Dereferencing.

                Now I'd like to retreive properties of controls having practically the same name. Instead of writing numorous nearly identical lines of code, I thought I could use this principal.

                If this is not possible in vb.Net, I will use Herfrieds' solution and create the Hashtable dynamically by scanning recursively through the forms-controlcollecti on.

                Maybe you have got another idea / approach.

                Kind regards,

                Michael

                "CJ Taylor" <nospam@blowgoa ts.com> wrote in message news:102pp7ri60 79cdc@corp.supe rnews.com...
                Are you trying to create a textbox control from a string variable as the name? I don't quite understand what your trying to do, but would be curiuos to learn what dereferencing is.

                -CJ
                "Michael Maes" <michael@merlot .com> wrote in message news:e8aLX8j8DH A.2044@TK2MSFTN GP10.phx.gbl...
                Hi,

                How would I handle Dereferencing in vb.Net 2003.

                Something like:
                Dim txt As TextBox = DirectCast("txt " & someStringVaria ble, TextBox)

                This sadly won't work because a type of string cannot be casted to a textbox.
                The "txt" + someStringVaria ble concatenation would represent a valid name of a textbox on the form.

                Thanks for any ideas,

                Michael

                Comment

                • Michael Maes

                  #9
                  Re: Dereferencing

                  Yeah, ... we'll have it "Maybe in Whidbey" ?!?!?
                  "CJ Taylor" <nospam@blowgoa ts.com> wrote in message news:102q3spdoh cqt72@corp.supe rnews.com...
                  I gotcha... Same thing could be done in JavaScript with the eval statement I believe... I remember doing something like this a couple times, just didn't know it was called derefrencing. Thanks for the pointer though!

                  -CJ
                  "Michael Maes" <michael@merlot .com> wrote in message news:OH5r4kl8DH A.2608@TK2MSFTN GP10.phx.gbl...
                  Hi CJ,

                  Until a couple of years ago I was a Coldfusion developer (up to v4.5).
                  In CFML there was a function 'Evaluate(Expre ssion)'.
                  Lets say you have a structure 'Language_Enu' and 'Language_Nl'
                  Both would have the same 'member variables', like eg 'SaveAndClose'

                  To retreive the value of 'SaveAndClose' you could then set eg a current_languag e_variable cLang (String) scoping the entire application. So you could fetch your var like:

                  Evaluate("Langu age_" & #current_langua ge_variable# & ".SaveAndClose" )

                  giving you the right value for the right language.

                  Since CFML (at that time) wasn't OOP, this only worked for Variables (I think -> long time ago!)

                  If I'm right, this type of operation is called Dereferencing.

                  Now I'd like to retreive properties of controls having practically the same name. Instead of writing numorous nearly identical lines of code, I thought I could use this principal.

                  If this is not possible in vb.Net, I will use Herfrieds' solution and create the Hashtable dynamically by scanning recursively through the forms-controlcollecti on.

                  Maybe you have got another idea / approach.

                  Kind regards,

                  Michael

                  "CJ Taylor" <nospam@blowgoa ts.com> wrote in message news:102pp7ri60 79cdc@corp.supe rnews.com...
                  Are you trying to create a textbox control from a string variable as the name? I don't quite understand what your trying to do, but would be curiuos to learn what dereferencing is.

                  -CJ
                  "Michael Maes" <michael@merlot .com> wrote in message news:e8aLX8j8DH A.2044@TK2MSFTN GP10.phx.gbl...
                  Hi,

                  How would I handle Dereferencing in vb.Net 2003.

                  Something like:
                  Dim txt As TextBox = DirectCast("txt " & someStringVaria ble, TextBox)

                  This sadly won't work because a type of string cannot be casted to a textbox.
                  The "txt" + someStringVaria ble concatenation would represent a valid name of a textbox on the form.

                  Thanks for any ideas,

                  Michael

                  Comment

                  • CJ Taylor

                    #10
                    Re: Dereferencing

                    I believe that is the answer for every feature in .NET. I've looked at Whidbey... It's nice, sure... Has some new controls that are fun. But so far Whidbey, Longhorn, and Yukon are supposed to be the 3 greatest tools ever invented. =)

                    They said the same thing about XP, now is FX, my curiousity is, what will it be after FX, I can't even think of creative names to use anymore.

                    I think it should be called.. Herfried.


                    "Michael Maes" <michael@merlot .com> wrote in message news:OybHdcm8DH A.2416@TK2MSFTN GP10.phx.gbl...
                    Yeah, ... we'll have it "Maybe in Whidbey" ?!?!?
                    "CJ Taylor" <nospam@blowgoa ts.com> wrote in message news:102q3spdoh cqt72@corp.supe rnews.com...
                    I gotcha... Same thing could be done in JavaScript with the eval statement I believe... I remember doing something like this a couple times, just didn't know it was called derefrencing. Thanks for the pointer though!

                    -CJ
                    "Michael Maes" <michael@merlot .com> wrote in message news:OH5r4kl8DH A.2608@TK2MSFTN GP10.phx.gbl...
                    Hi CJ,

                    Until a couple of years ago I was a Coldfusion developer (up to v4.5).
                    In CFML there was a function 'Evaluate(Expre ssion)'.
                    Lets say you have a structure 'Language_Enu' and 'Language_Nl'
                    Both would have the same 'member variables', like eg 'SaveAndClose'

                    To retreive the value of 'SaveAndClose' you could then set eg a current_languag e_variable cLang (String) scoping the entire application. So you could fetch your var like:

                    Evaluate("Langu age_" & #current_langua ge_variable# & ".SaveAndClose" )

                    giving you the right value for the right language.

                    Since CFML (at that time) wasn't OOP, this only worked for Variables (I think -> long time ago!)

                    If I'm right, this type of operation is called Dereferencing.

                    Now I'd like to retreive properties of controls having practically the same name. Instead of writing numorous nearly identical lines of code, I thought I could use this principal.

                    If this is not possible in vb.Net, I will use Herfrieds' solution and create the Hashtable dynamically by scanning recursively through the forms-controlcollecti on.

                    Maybe you have got another idea / approach.

                    Kind regards,

                    Michael

                    "CJ Taylor" <nospam@blowgoa ts.com> wrote in message news:102pp7ri60 79cdc@corp.supe rnews.com...
                    Are you trying to create a textbox control from a string variable as the name? I don't quite understand what your trying to do, but would be curiuos to learn what dereferencing is.

                    -CJ
                    "Michael Maes" <michael@merlot .com> wrote in message news:e8aLX8j8DH A.2044@TK2MSFTN GP10.phx.gbl...
                    Hi,

                    How would I handle Dereferencing in vb.Net 2003.

                    Something like:
                    Dim txt As TextBox = DirectCast("txt " & someStringVaria ble, TextBox)

                    This sadly won't work because a type of string cannot be casted to a textbox.
                    The "txt" + someStringVaria ble concatenation would represent a valid name of a textbox on the form.

                    Thanks for any ideas,

                    Michael

                    Comment

                    • Cor

                      #11
                      Re: Dereferencing


                      [color=blue]
                      >I think it should be called.. Herfried.[/color]

                      LOL


                      Comment

                      • Michael Maes

                        #12
                        Re: Dereferencing

                        do you mean the dutch word ;-)

                        "Cor" <non@non.com> wrote in message
                        news:eL$Wart8DH A.3348@TK2MSFTN GP09.phx.gbl...
                        |
                        |
                        | >I think it should be called.. Herfried.
                        |
                        | LOL
                        |
                        |


                        Comment

                        • Cor

                          #13
                          Re: Dereferencing

                          "> do you mean the dutch word ;-)[color=blue]
                          > LOL[/color]

                          Yes that is a Dutch word, it means fun, or are you thinking on the almost
                          the same word with a U.

                          Certainly not, not for CJ and also not for Herfried greath guys,

                          :-)

                          Cor




                          Comment

                          • Zanna

                            #14
                            Re: Dereferencing

                            "Michael Maes" <michael@merlot .com> wrote in message

                            <q>
                            Something like:
                            Dim txt As TextBox = DirectCast("txt " & someStringVaria ble, TextBox)

                            This sadly won't work because a type of string cannot be casted to a
                            textbox.
                            The "txt" + someStringVaria ble concatenation would represent a valid name of
                            a textbox on the form.
                            </q>

                            You can do a loop on Me.Controls and searching for the Item.Name = "txt" +
                            someStringVaria ble.
                            Than you can cast the item found to TextBox.

                            --
                            Math Parser : http://www.neodatatype.net


                            Comment

                            • Cor

                              #15
                              Re: Dereferencing

                              Hi Michael,

                              Or maybe you are a Dutch speaker, because your name sounds very Belgian.

                              LOL means Laugh On Line but when you are a Dutch speaker, then you know that
                              is the same as the dutch lol.

                              Cor


                              Comment

                              Working...