Creating variables at Run-time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thiago777
    New Member
    • May 2007
    • 89

    Creating variables at Run-time

    Is this possible in VB? for example, in PHP you can use the "$$" like $$future_var in place of a variable name that will be created only later.

    thanks.
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    I don't believe this is the case unless you create application variables or ones created in classes. HTH.

    Comment

    • thiago777
      New Member
      • May 2007
      • 89

      #3
      Originally posted by kenobewan
      I don't believe this is the case unless you create application variables or ones created in classes. HTH.
      Sorry but I didnt understand you. What case are you talking about?

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        Just meaning your question, the case in point.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          To what benefit does that offer?
          You could make an empty/blank varriable if you wanted.

          Comment

          • thiago777
            New Member
            • May 2007
            • 89

            #6
            Originally posted by Plater
            To what benefit does that offer?
            You could make an empty/blank varriable if you wanted.
            Sometimes creating variables dinamically is the only solution for certain problems.
            The new variable (created in run-time) could have the name specified by another source for example.
            I've already used this in PHP.. but I dont know if it works in vb.net. In php, as I said, you use the $$ symbol to specify the future identificator.

            Comment

            • thiago777
              New Member
              • May 2007
              • 89

              #7
              Originally posted by Plater
              To what benefit does that offer?
              You could make an empty/blank varriable if you wanted.
              And in those cases you cant make a blank variable, once you dont know the name of it yet. It is named dynamically.

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Why do you need the name to change?
                I really don't see what that offers.
                I mean you could create a Control object.
                Then assign the Name property of it and stick spare data in the Tag property.

                Or better yet create a Dictionary or some sort of name/value pairing.

                Comment

                • kenobewan
                  Recognized Expert Specialist
                  • Dec 2006
                  • 4871

                  #9
                  Sometimes creating variables dinamically is the only solution for certain problems.
                  I dont really see this either when you can variables "at run time" in the page load or page init events. Please give examples.

                  Comment

                  • thiago777
                    New Member
                    • May 2007
                    • 89

                    #10
                    Originally posted by kenobewan
                    I dont really see this either when you can variables "at run time" in the page load or page init events. Please give examples.
                    This is called Variable Variables. Take a look here:



                    I wanted the same effect but in VB .Net

                    thanks

                    Comment

                    • Plater
                      Recognized Expert Expert
                      • Apr 2007
                      • 7872

                      #11
                      That still sounds similar to a dictionary.
                      And as far as just variables, it still doesn't seem beneficial, more of an addional complexity that makes code harder to read.
                      Now, being able to refer to classes by a string (Reflection), seems rather usefull.

                      But yeah just make a dictionary?
                      myd.add("foo"," bar");

                      string whatfoois=myd["foo"];

                      Comment

                      Working...