Guest dinobuiatti Posted August 28, 2002 Posted August 28, 2002 Let's say I had 5 text boxes named text1, text2, text3......text5. Assuming I wanted to set their values to 1,2,3,4, and 5, I could do the following: text1.text = "1" text2.text = "2" text3.text = "3" text4.text = "4" text5.text = "5" But a better way would be to do it dynamically. Something like: ' declare variables dim countervalue, textfieldname ' clear variable countervalue = 1 ' for loop for countervalue = 1 to 5 ' create reference to text field textfieldname = text & countervalue ' set text value for current text field textfieldname.text = countervalue Next Of course in my example, the the text1.text is evaluated as a text instead of a reference to the text field How can I build a dynamic structure that refers to text fields and other controls. Thnx Dino B Quote
Guest Cogen Posted August 28, 2002 Posted August 28, 2002 I really am not sure if this is what your looking for, but if you create a control array, you can dynamically create new controls. An example of textboxes would be ... Sub cmdCreateNewTextBox_Click() Static intCount As Integer 'Get the next array index number (new controls index) intCount = intCount + 1 'Create the new control dynamically Load txtInput(intCount) 'Set the position for upper-left corner of new control so 'it won't fall on top of previous dynamically created 'controls txtInput(intCount).Top = txtInput(intCount - 1).Top + 495 txtInput(intCount).Left = txtInput(intCount - 1).Left 'Insert a value as you did in your example txtInput(intCount).text = intCount 'Now, display the new control txtInput(intCount).Visible = True End Sub You could dynamically unload the textboxes using ... Sub cmdUnloadControl_Click Unload txtInput(3) 'or a loop, depending on what you want. End Sub Quote
Guest dinobuiatti Posted August 28, 2002 Posted August 28, 2002 Let me simplify. lets say i have one textbox. textbox1 when i do the following from a submit button, it wont compile dim intergervalue intervalue = 1 textbox(intervalue).text = "value" how would i do this thank you dinob Quote
ChiefRedBull Posted August 28, 2002 Posted August 28, 2002 Let me simplify too. Use a control array - like Cogen said - then you can reference an array of controls via an Index property. Alternatively, create an array of generic Control object variables, then fill it with references to any controls on your form that you want to use in your routines. Quote
Guest dinobuiatti Posted August 28, 2002 Posted August 28, 2002 Control arrays are not supported in .NET Quote
Flyguy Posted August 28, 2002 Posted August 28, 2002 Would be nice if you told us a little earlier you were using vb.net Quote
*Gurus* divil Posted August 29, 2002 *Gurus* Posted August 29, 2002 Control arrays are perfectly possible in .NET, they're just not supported by the designers. Look for this in newer versions. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.