Array of textbox

  • Thread starter Thread starter Angel López
  • Start date Start date
A

Angel López

How to do this with Vb.net 2008???

myNumber=1+ Int(Rnd()*90)
text(myNumber).backcolor=vbRed

Tanks

Angel
 
Angel López said:
How to do this with Vb.net 2008???

myNumber=1+ Int(Rnd()*90) text(myNumber).backcolor=vbRed

Put all textboxes in an array before, for example:

Public Class Form1

Dim textboxes As TextBox()

Private Sub Form1_Load( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load

textboxes = New TextBox() {TextBox1, TextBox2, TextBox3}
End Sub

End Class


(no, there are no "control arrays" anymore...)


Armin
 
How to do this with Vb.net 2008???

myNumber=1+ Int(Rnd()*90)
text(myNumber).backcolor=vbRed

You can't make a control array in design mode, but you can emulate it
by creating the controls at run time.

I have created an array of picturebox controls to display a variable
number of images on a form. I did this in C#.NET but I don't see why
it can't be done with VB.NET.
 
Zack,

In my idea are you mixing up using the designer to create something and
runtime.

You can make something at runtime by using reflection, however mostly and
more save is to do it at design time by code.

Both Armin and Patrice give samples for this, where I like the sample from
Armin the most because he uses the designer to create the labels.
As long as that the labels are not moving over the screen, then there is in
my idea not any reason to make them dynamicly.

jmo

Cor

How to do this with Vb.net 2008???

myNumber=1+ Int(Rnd()*90)
text(myNumber).backcolor=vbRed

You can't make a control array in design mode, but you can emulate it
by creating the controls at run time.

I have created an array of picturebox controls to display a variable
number of images on a form. I did this in C#.NET but I don't see why
it can't be done with VB.NET.
 
Armin,

I hope you don't mind, just your opinion, would it not be better to use the
text

"There are no VB6 control arrays anymore"

Probably like you I think the OP is a classic VB6 user, however others who
never used that can be confused.

You show a true control arrays in your code.

Just writing what I was thinking when I saw your text.

Cor
 
Cor Ligthert said:
Armin,

I hope you don't mind, just your opinion, would it not be better to
use the text

"There are no VB6 control arrays anymore"

Probably like you I think the OP is a classic VB6 user, however
others who never used that can be confused.

You show a true control arrays in your code.

Just writing what I was thinking when I saw your text.

Hi Cor, :-)

sorry, but this is really not my problem. I answered Angel who obviously
knows what "control arrays" mean in this context. I really can not care
about any reader that will read my message in the future without knowing
what we are talking about. Of course you are right that I meant "VB6 control
arrays". Thx for the correction on behalf of all future readers.

BTW, the term was in double quotes, and, if I had meant an array of
controls I would have named them array of controls. (w/o double qoutes) ;-)

You should have better mentioned that 'textboxes' should not be declared
locally but outside the method as a field of the class (which I was too lazy
to correct). ;-)

There are worse things as we both know. :)


Armin
 
Back
Top