altering variable name

Hi!

I need to alter a variable name.

The scenario is: i have a lot of text box, so i want to read the text of each box and load all in a same string.

So, i think to use a for loop... but... if i work in this way, it's necessary alter the name of text box...

Can anybody help me


Answer this question

altering variable name

  • B123456H

    As Marc suggested, you can just put the textboxes into an array or any structure you desire and just loop on them.

    Thanks,
      Ayman Shoukry
      VC++ Team

  • Shelto

     Marcelo Shiba wrote:
    My english is really bad... =P

    But i'll try to explain better...

    I have 10 textboxes, and i need to read the text of each one. How can i do this efficiently


    You should also state what technologies you are using.
    For Example, ATL, WTL, MFC, VC++.NET, Win32 API, etc.

  • GeoffChambers

    My english is really bad... =P

    But i'll try to explain better...

    I have 10 textboxes, and i need to read the text of each one. How can i do this efficiently

  • Ronaldo444

    Many thanks!!

  • Marco H

    How can i put the textboxes into an array

    I'm using vc++ .net.

    Many thanks!

  • kolya

    You cannot and do not need to change a variable name. Variables mean nothing in C++ to the program once it is compiled. They are merely a means for us humans to remember what goes where when we write code.

    txtBox.Name = "Bleah"

    the variable name is txtBox and is referenced as txtBox. You don't even need to give textboxs names but you could easily do put the textboxe controls in an array and loop over the array getting the values. Your english/description of the problem were not very detailed or coherent so I cannot really elaborate much further as I have no idea what technologies you are actually trying to work with.

  • MartinPare

    This code may need a bit of syntax adaptation because it is C#. C++ and C# is mostly similar except for the differences ;)
    with your other control declarations  so it is accessible throughout the whole form


    TextBox[] MyTextBoxes = new TextBox[] { };

    somewhere in your Code
    MyTextBoxes = new TextBox[10];
    for (Int32 i=0; i<MyTextBoxes.Length; i++)
    {
       MyTextBoxes[ i ] = new TextBox();
      MyTextBoxes[ i ].Location = new Point(10, i*20);
      Controls.Add(MyTextBoxes[ i ]);
    }

    in another part of your form
    String Values = "":
    for (Int32 i=0; i<MyTextBoxes.Length; i++)
    {
        Values += MyTextBoxes[ i ].Text + ", ";
    }
    MessageBox.Show(Values);

     



  • altering variable name