From: Tom Shelton on
On 2009-10-05, C <wrong.address.1(a)gmail.com> wrote:
> On 4 loka, 23:58, "J.B. Moreno" <pl...(a)newsreaders.com> wrote:
>> <wrong.addres...(a)gmail.com> wrote:
>> > "J.B. Moreno" <pl...(a)newsreaders.com> wrote:
>> -snip-
>>
>> > > It's basically a more powerful way of doingcontrolarrays. �But it is
>> > > slightly different, so an automatic upgrade won't be using this method.
>>
>> > I found the *.designer.vb where this stuff is.
>>
>> Like I said in the part I snipped, you don't want to go editing the
>> designer file anymore than you want to be opening a frm file in a text
>> editor and editing it -- it's possible, but absent specific reasons and
>> experience, not a good idea.
>>
>>
>>
>>
>>
>> > � � � � Me._Text2_3 = New System.Windows.Forms.TextBox
>> > � � � � Me._Text2_2 = New System.Windows.Forms.TextBox
>> > � � � � Me._Text2_1 = New System.Windows.Forms.TextBox
>> > � � � � Me._Text2_0 = New System.Windows.Forms.TextBox
>> > � � � � Me._Text1_15 = New System.Windows.Forms.TextBox
>> > � � � � Me._Text1_14 = New System.Windows.Forms.TextBox
>> > � � � � Me._Text1_13 = New System.Windows.Forms.TextBox
>> > � � � � Me._Text1_12 = New System.Windows.Forms.TextBox
>>
>> > followed by
>>
>> > � � � � Me.Text2.SetIndex(Me._Text2_12, CType(12, Short))
>> > etc.
>>
>> > Fortunately this has been done by the conversion wizard. If I have to
>> > do this myself, what is the right way of doing it? For example, my
>> > Form2 needs 16 textboxes called Text1, 16 of Text2, 16 Label1 and 16
>> > Label2. Then there are some commands for calculations. How should I do
>> > this? In VB6, it could be done nicely and cleanly.
>>
>> You'd do it in the designer -- dragging the TextBox from the ToolBox to
>> the appropriate place on your form. �Pretty much like you did in VB6
>> originally.
>
> Yes, I can drag the textbox and create 32 of them but how do I get
> them into an array without messing with the designer.vb?
>

Add a sub new to your Forms.vb file, then you can add the code there. The
IDE is pretty smart about that - even adding the call to InitializeComponets.

Alternativly, Form_Load :)


--
Tom Shelton
From: C on
On 5 loka, 18:37, Tom Shelton <tom_shel...(a)comcastXXXXXXX.net> wrote:
> On 2009-10-05, C <wrong.addres...(a)gmail.com> wrote:
>
>
>
>
>
> > On 4 loka, 23:58, "J.B. Moreno" <pl...(a)newsreaders.com> wrote:
> >> <wrong.addres...(a)gmail.com> wrote:
> >> > "J.B. Moreno" <pl...(a)newsreaders.com> wrote:
> >> -snip-
>
> >> > > It's basically a more powerful way of doingcontrolarrays.  But it is
> >> > > slightly different, so an automatic upgrade won't be using this method.
>
> >> > I found the *.designer.vb where this stuff is.
>
> >> Like I said in the part I snipped, you don't want to go editing the
> >> designer file anymore than you want to be opening a frm file in a text
> >> editor and editing it -- it's possible, but absent specific reasons and
> >> experience, not a good idea.
>
> >> >         Me._Text2_3 = New System.Windows.Forms.TextBox
> >> >         Me._Text2_2 = New System.Windows.Forms.TextBox
> >> >         Me._Text2_1 = New System.Windows.Forms.TextBox
> >> >         Me._Text2_0 = New System.Windows.Forms.TextBox
> >> >         Me._Text1_15 = New System.Windows.Forms.TextBox
> >> >         Me._Text1_14 = New System.Windows.Forms.TextBox
> >> >         Me._Text1_13 = New System.Windows.Forms.TextBox
> >> >         Me._Text1_12 = New System.Windows.Forms.TextBox
>
> >> > followed by
>
> >> >         Me.Text2.SetIndex(Me._Text2_12, CType(12, Short))
> >> > etc.
>
> >> > Fortunately this has been done by the conversion wizard. If I have to
> >> > do this myself, what is the right way of doing it? For example, my
> >> > Form2 needs 16 textboxes called Text1, 16 of Text2, 16 Label1 and 16
> >> > Label2. Then there are some commands for calculations. How should I do
> >> > this? In VB6, it could be done nicely and cleanly.
>
> >> You'd do it in the designer -- dragging the TextBox from the ToolBox to
> >> the appropriate place on your form.  Pretty much like you did in VB6
> >> originally.
>
> > Yes, I can drag the textbox and create 32 of them but how do I get
> > them into an array without messing with the designer.vb?
>
> Add a sub new to your Forms.vb file, then you can add the code there.  The
> IDE is pretty smart about that - even adding the call to InitializeComponets.
>
> Alternativly, Form_Load :)
>
> --
> Tom Shelton- Piilota siteerattu teksti -
>
> - Näytä siteerattu teksti -

Sorry, I cannot understand this at all. What sub new do I add and what
do I write in the subroutine? In VB6, control arrays were formed
straight by copying a control to another. What do I have to do here in
VB Express 2008? Thanks.
From: J.B. Moreno on
<wrong.address.1(a)gmail.com> wrote:

> On 4 loka, 23:58, "J.B. Moreno" <pl...(a)newsreaders.com> wrote:
-snip-
> > You'd do it in the designer -- dragging the TextBox from the ToolBox to
> > the appropriate place on your form. �Pretty much like you did in VB6
> > originally.
>
> Yes, I can drag the textbox and create 32 of them but how do I get
> them into an array without messing with the designer.vb?

Instead of an array, you have a collection -- the collection is created
automatically based upon the fact that they share a common "parent"
control (a container control).

Take for example a Tab control -- you drag that to to the form from the
ToolBox, then you drag your TextBoxes from the ToolBox to the Tab.
Presto, you have a collection of TextBoxes.

You can do the same thing with any container -- split control, group
box, panel, tab. Anything that can hold another control.

> > BTW - I'd recommend changing the names (in the designer) of the various
> > controls to something appropriate.
>
> You mean txtVolume and txtDensity instead of Text1 and Text2?

Exactly.

--
J.B. Moreno
From: C on
On 6 loka, 05:39, "J.B. Moreno" <pl...(a)newsreaders.com> wrote:
> <wrong.addres...(a)gmail.com> wrote:
> > On 4 loka, 23:58, "J.B. Moreno" <pl...(a)newsreaders.com> wrote:
> -snip-
> > > You'd do it in the designer -- dragging the TextBox from the ToolBox to
> > > the appropriate place on your form.  Pretty much like you did in VB6
> > > originally.
>
> > Yes, I can drag the textbox and create 32 of them but how do I get
> > them into an array without messing with the designer.vb?
>
> Instead of an array, you have a collection -- the collection is created
> automatically based upon the fact that they share a common "parent"
> control (a container control).

If I understand right, a collection will not be an array, or in other
words, I cannot refer to the 4th element as Text1(3).Text. In that
case, it won't serve my purpose. I need to do mathematical
calculations with vectors and show some numbers in text boxes, so I
need to read the values in Text1(k).Text and show calculated values in
Text2(i).Text. The same number of labels are made visible and their
text (caption) is often taken from an input file.

You are suggesting that I could put these in a frame or some
container, so that they will all belong to one group (collection).
This would not be a problem, but I would like to address the elements
of the collection by an index.

What exactly has the conversion wizard done? I am able to make the
same calculations in the converted code, but I don't understand very
much of what the new code means. It has given separate names to each
label and text box. Then it has formed the arrays because the code
addressing Text1(k).Text has not changed.

>
> Take for example a Tab control -- you drag that to to the form from the
> ToolBox, then you drag your TextBoxes from the ToolBox to the Tab.
> Presto, you have a collection of TextBoxes.
>
> You can do the same thing with any container -- split control, group
> box, panel, tab.  Anything that can hold another control.
>
> > > BTW - I'd recommend changing the names (in the designer) of the various
> > > controls to something appropriate.
>
> > You mean txtVolume and txtDensity instead of Text1 and Text2?
>
> Exactly.
>
> --
> J.B. Moreno

Thanks. I understand the VB.net terminology quite poorly, which is one
reason why I am asking these stupid questions.
From: Armin Zingler on
C schrieb:
>
> Sorry, I cannot understand this at all. What sub new do I add and what
> do I write in the subroutine? In VB6, control arrays were formed
> straight by copying a control to another. What do I have to do here in
> VB Express 2008? Thanks.


Some things you should know:

- You've seen there are two files for one Form. The (usually hidden) designer part
and the visible code file.

- The designer part contains Sub InitializeComponent that must be called in the
Form's constructor (Sub New) because it creates the controls and so on.

- With "normal" classes, if you don't write your own constructor(s), the VB compiler
automatically adds a default constructor which just calls the base class constructor.
This constructor is compiled into the assembly (exe/dll) but it's not visible in the
source code.

- If you add a new Form to the project, it does not have a visible constructor, too.
With a Form class, VB also creates a default constructor but that one also contains
a call to InitializeComponent.

- If you add your own constructor to your own Form class, do it in the form1.vb
file (not in the designer file). You must not forget to call InitializeComponent
there. Otherwise all controls were missing. And that's what Tom
meant: As soon as you add your own constructor, the IDE automatically inserts
the call to InitializeComponent.

- With upgraded projects it's a little bit different because form1.designer.vb does
include a constructor (also calling InitializeComponent). If you added your own
constructor in form1.vb, you'd have two of them (with same signature) which is
not allowed.

Back to your goal to create an array of Textboxes. You have to do it inside
the constructor after calling InitializeComponent.

So, inside Form1.vb add:

private myTextboxes as textbox()

And inside Form1.designer.vb change the constructor to make it look like this:

sub new
InitializeComponent

mytextboxes = new textbox() {text0, text1, text2} '<<<<<<< line to add
end sub

Sometimes there is already a call to "class_initialize_renamed" which you find
inside form1.vb. If that's the case, you can add the line "mytextboxes =..."
in sub class_initialize_renamed instead of directly in Sub New.


Later in code, you can refer to the textboxes by index by writing

mytextboxes(0).text = "I'm a textbox"



--
Armin