Home All Groups Group Topic Archive Search About
Author
10 Sep 2006 12:56 PM
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

Author
10 Sep 2006 1:35 PM
rowe_newsgroups
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

simon wrote:
Show quoteHide quote
> 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
Author
10 Sep 2006 2:10 PM
Cor Ligthert [MVP]
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



Show quoteHide quote
"rowe_newsgroups" <rowe_em***@yahoo.com> schreef in bericht
news:1157895302.882824.42110@e3g2000cwe.googlegroups.com...
> 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
>
> simon wrote:
>> 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
>
Author
10 Sep 2006 3:07 PM
simon
Cor Ligthert [MVP] wrote:
Show quoteHide quote
> 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" <rowe_em***@yahoo.com> schreef in bericht
> news:1157895302.882824.42110@e3g2000cwe.googlegroups.com...
> > 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
> >
> > simon wrote:
> >> 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
> >
Author
10 Sep 2006 3:07 PM
simon
rowe_newsgroups wrote:
Show quoteHide quote
> 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
>
> simon wrote:
> > 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
Author
10 Sep 2006 5:41 PM
Herfried K. Wagner [MVP]
"simon" <spain***@gmail.com> schrieb:
> 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>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>