|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Creating an array of textbox objectsI am working on a project where I have a set of textboxs and some butons and I would like to have a way of keeping the textboxes using an array to make easier my data input. THis is what I am trying to do: Create an array of 4, 5 or more textboxes and collect the information using a for-next loop for t =1 to 4 infosr &= TEXTBOX(T).TEXT next t messagebox.show(infostr) -------------- I am using VB2005 Thanks, -hb Assuming your textbox names start with txt, I think this would work...
Dim Infosr as String Dim myCont as New Control For Each myCont in Me.Controls If myCont.Name.StartsWith("txt") Then Infosr &= myCont.Text End If Next myCont Hector,
The most easy way in my idea, dim myControlArrayToUse() as Control = {TextBox1, Txsbal, Texbox3, WhateverName} dim myArray(3) as string for i as integer from 0 to 3 myArray(i) = myControlArrayToUse(i).text next I hope this helps, Cor Show quoteHide quote "Hector M Banda" <hec***@mxlweb.com> schreef in bericht news:eHzczEqBHHA.4256@TK2MSFTNGP04.phx.gbl... > Hi all, > I am working on a project where I have a set of textboxs and some butons > and I would like to have a way of keeping the textboxes using an array to > make easier my data input. > > THis is what I am trying to do: > > Create an array of 4, 5 or more textboxes and collect the information > using a for-next loop > > for t =1 to 4 > infosr &= TEXTBOX(T).TEXT > next t > > messagebox.show(infostr) > > -------------- > > > I am using VB2005 > > Thanks, > > -hb > > As long as you give all of your textboxes the same prefix name ...
Dim Prefix as string = "txtboxnameprefix" for t =1 to 4 inforsr &= CType(Mel.Controls.Item(Prefix & Cstr(t),TextBox).Text next t In my opinion, you'd be much better off using a collection. For
example: Dim ControlList As New Collection() ControlList.Add(Me.SomeTextBox, "SomeTextBox") .... repeat the add method for every textbox you want to do something with Then later in your code you could: Dim TempTextbox As TextBox For Each TempTextbox In ControlList SomeVar = TempTextbox.Text 'or TempTextbox.Value = SomeNewValue 'or TempTextbox.Visible = SomeFunctionCallToCheckSecurity() Next We do this in our base forms for checking security on textboxes. It's a simple and elegant way to handle some common functionality on a variable number of controls. Hope this helps.
Thread.Sleep slowing down the whole application
Play wavs in VB2005. "how to split a string in a random way" Extract Single Record from Dataset filled from SP Output Creating text boxes on the fly? Compression namespace for Array Able .NET ? GUIDS not creating correctly in vb.net Can I add them to the context menu and programmically copy them to the main menu Getting IE Page Contents |
|||||||||||||||||||||||