By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,684 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,684 IT Pros & Developers. It's quick & easy.

look for an operator

P: n/a
Hi,
I've many texboxes called txt1,txt2,...,txtn, the number isn't known at the
design time because they are created by code.
I'm looking for a way to use them folowing of an iterator i
txti.text="value"

In another languages (vb6???) I used the operator &: txt&i
how does it work in vb.net?

Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Cor
Hi Touf,
I did made a sample with chekboxes yesterday, but it is of course almost the
same with textboxes.
\\\
Private myCheckbox(10) As CheckBox
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'you need for this sample to drag a button on the form
Dim start As Integer = 4
Dim top As Integer = 18
Dim i As Integer
For i = 1 To 10
myCheckbox(i) = New CheckBox
myCheckbox(i).TextAlign = ContentAlignment.MiddleCenter
myCheckbox(i).Width = 40
myCheckbox(i).Height = 20
myCheckbox(i).Location = New System.Drawing.Point(start, top)
myCheckbox(i).Text = i.ToString
myCheckbox(i).Cursor = Cursors.Hand
Me.GroupBox1.Controls.Add(myCheckbox(i))
AddHandler myCheckbox(i).Click, AddressOf myCheckBox_Click
start = start + 40
If i = 5 Then
top = top + 20
start = 4
End If
Next
End Sub
Private Sub myCheckBox_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim chk As CheckBox
chk = DirectCast(sender, CheckBox)
Dim i As String = chk.Text
End Sub
Private Sub Button1_Click _
(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim a As New System.Text.StringBuilder
a.Remove(0, a.Length)
Dim i As Integer
For i = 1 To 10
If myCheckbox(i).Checked Then
a.Append(i.ToString)
End If
Next
MessageBox.Show(a.ToString)
End Sub
///
I hope this helps a little bit
Cor
Nov 20 '05 #2

P: n/a
Hi Touf,

One way is to add them to an array or ArrayList when you create them.

If you use an array, you'll be able to give it the correct type but you'll
have to keep ReDimensioning it as you go, or create it large enough for the
maximum possible and then ReDim down to size.
Dim aoTestBoxes (MoreThanEnough) As TestBox
... Add to aoTestBoxes ...
ReDim Preserve aoTestBoxes (NumTextBoxes)
aoTestBoxes (I).Text = "value"

If you use an ArrayList, it will grow as required but you'll have to cast
the items in order to use them:
Dim alTestBoxes As ArrayList
DirectCast (alTestBoxes (I), TextBox).Text = "value"

Regards,
Fergus
Nov 20 '05 #3

P: n/a
"touf" <to******@hotmail.com> schrieb
Hi,
I've many texboxes called txt1,txt2,...,txtn, the number isn't known
at the design time because they are created by code.
I'm looking for a way to use them folowing of an iterator i
txti.text="value"

In another languages (vb6???) I used the operator &: txt&i
how does it work in vb.net?


Add the textboxes to an array, then you can use i as the index in the array,
and you can give the textboxes expressive names (if you want).
--
Armin

Nov 20 '05 #4

P: n/a
Thanks.

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:e9**************@tk2msftngp13.phx.gbl...
Hi Touf,

One way is to add them to an array or ArrayList when you create them.

If you use an array, you'll be able to give it the correct type but you'll have to keep ReDimensioning it as you go, or create it large enough for the maximum possible and then ReDim down to size.
Dim aoTestBoxes (MoreThanEnough) As TestBox
... Add to aoTestBoxes ...
ReDim Preserve aoTestBoxes (NumTextBoxes)
aoTestBoxes (I).Text = "value"

If you use an ArrayList, it will grow as required but you'll have to cast the items in order to use them:
Dim alTestBoxes As ArrayList
DirectCast (alTestBoxes (I), TextBox).Text = "value"

Regards,
Fergus

Nov 20 '05 #5

P: n/a
"touf" <to******@hotmail.com> scripsit:
I've many texboxes called txt1,txt2,...,txtn, the number isn't known at the
design time because they are created by code.
I'm looking for a way to use them folowing of an iterator i
txti.text="value"


Creating Control Arrays in Visual Basic .NET and Visual C# .NET
<http://msdn.microsoft.com/library/?url=/library/en-us/dv_vstechart/html/vbtchCreatingControlArraysInVisualBasicNETVisualCN ET.asp>

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.