how to write ?

  • Thread starter Thread starter simon
  • Start date Start date
S

simon

Hi! I am beginner of VB.net When I wrote with VB6, I copy and paste
some same controls, the IDE will paste a assay control such as
"label1(1),label1(2)......" . So I can control them total with the "for
.....Next".
But in VB.net When I do the same thing ,IDE will give me such as
"label1,label2......". then how can I do as the VB6?
for example:
In VB6

Private Sub Form1_Load
For i = 1 To 5
TextBox1(i) = ""
Nex
End Sub

In VB.net I just can write as follow:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim i As Integer
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""

End Sub

How can I wirte in VB.net with "for next"??

Thanks a Lot!!

Simon
 
Unfortunately for all of us control array were scrapped int .NET.
However a few searches on this newsgroup or on MSDN will show ways to
mimic control arrays. But to answer your question try out the below
code. Be warned that the code can lead to runtime errors if you're not
careful typing, and can be difficult to maintain.

Dim i As Integer

For i = 1 To 5
Me.Controls("TextBox" & i).Text = ""
Next i

Thanks,

Seth Rowe
 
Rowe,
Unfortunately for all of us control array were scrapped int .NET.

This is often misinterpreted in my opinion. There is not any more the
designer part of VB6 with the control properties.

There are now more control arrays in Net as there have ever been in VB6,
while mimic that array in even a better way is very easy
\\\.
Dim MySpecialControls() As Control = {Button1, TextBox1}
For Each ctr As Control In MySpecialControls
ctr.Text = "Hello"
Next
///

But this is only one of the it seems now endless possibilities to use conrol
arrays in .Net.

I hope this gives an idea,

Cor
 
rowe_newsgroups said:
Unfortunately for all of us control array were scrapped int .NET.
However a few searches on this newsgroup or on MSDN will show ways to
mimic control arrays. But to answer your question try out the below
code. Be warned that the code can lead to runtime errors if you're not
careful typing, and can be difficult to maintain.

Dim i As Integer

For i = 1 To 5
Me.Controls("TextBox" & i).Text = ""
Next i

Thanks,

Seth Rowe
 
Cor said:
Rowe,


This is often misinterpreted in my opinion. There is not any more the
designer part of VB6 with the control properties.

There are now more control arrays in Net as there have ever been in VB6,
while mimic that array in even a better way is very easy
\\\.
Dim MySpecialControls() As Control = {Button1, TextBox1}
For Each ctr As Control In MySpecialControls
ctr.Text = "Hello"
Next
///

But this is only one of the it seems now endless possibilities to use conrol
arrays in .Net.

I hope this gives an idea,

Cor
 
simon said:
When I wrote with VB6, I copy and paste
some same controls, the IDE will paste a assay control such as
"label1(1),label1(2)......" . So I can control them total with the "for
....Next".
But in VB.net When I do the same thing ,IDE will give me such as
"label1,label2......". then how can I do as the VB6?

Accessing controls by their names or indices
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en>
 
Back
Top