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

Serious discussion about removing dynamically controls

P: n/a
Cor
Hi,
I start a new thread about a discussion from yesterday (or for some of us
this morning). It was a not so nice discussion about dynamically removing
controls from a panel or what ever.
It started by an example from me, that was far from complete and with typing
errors, but basically it had the meaning to show that removing controls
reversible was the nicest method.

This was a lets say conclusion (but what is that in a newsgroup) in a
discussion some weeks ago in this newsgroup. The method was contributed by
Armin. I found it brilliant and since that time I call this the method
Armin.

Jack did totally disagree with this method and did after a while contribute
some code.

Therefore I send both code's to this newsgroup in this new thread. I think
it is good to talk professionally about it. So it is not the code Cor, Nick,
Armin or Jack. Just the method "reverse For next loop", against the "While
end while loop" for removing controls dynamically.

I don't want to start with my + of - points about the methods, maybe I will
give that, but I hope that it will come automatically in this newsgroup

The code that Jack has given some contribution for me, because I did not
know "removeAT" exist. But I always do the things that I do plus in the same
way minus. So I doubt if I will use it, but for the example I did use
"removeAT" (I think it is nicer). Please don't start a discussion about
that. The question is the "While end while" against reversal "For next".

"While end While"
Dim idx As Integer
idx = 0
While idx < Me.Panel1.Controls.Count ' while in bounds
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
Else
idx = idx + 1 ' otherwise advance to next control
End If
End While
-----------------
"For index Next reversal"
Dim idx As Integer
For idx = Me.Panel1.Controls.Count - 1 To 0 Step -1
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
End If
Next
I hope this contribute something
Cor


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


P: n/a
I favour the reversal code which I tend to use a lot because it's cleaner
and generally saves you getting into problems.

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.
"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
Hi,
I start a new thread about a discussion from yesterday (or for some of us
this morning). It was a not so nice discussion about dynamically removing
controls from a panel or what ever.
It started by an example from me, that was far from complete and with typing errors, but basically it had the meaning to show that removing controls
reversible was the nicest method.

This was a lets say conclusion (but what is that in a newsgroup) in a
discussion some weeks ago in this newsgroup. The method was contributed by
Armin. I found it brilliant and since that time I call this the method
Armin.

Jack did totally disagree with this method and did after a while contribute some code.

Therefore I send both code's to this newsgroup in this new thread. I think
it is good to talk professionally about it. So it is not the code Cor, Nick, Armin or Jack. Just the method "reverse For next loop", against the "While
end while loop" for removing controls dynamically.

I don't want to start with my + of - points about the methods, maybe I will give that, but I hope that it will come automatically in this newsgroup

The code that Jack has given some contribution for me, because I did not
know "removeAT" exist. But I always do the things that I do plus in the same way minus. So I doubt if I will use it, but for the example I did use
"removeAT" (I think it is nicer). Please don't start a discussion about
that. The question is the "While end while" against reversal "For next".

"While end While"
Dim idx As Integer
idx = 0
While idx < Me.Panel1.Controls.Count ' while in bounds
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
Else
idx = idx + 1 ' otherwise advance to next control
End If
End While
-----------------
"For index Next reversal"
Dim idx As Integer
For idx = Me.Panel1.Controls.Count - 1 To 0 Step -1
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
End If
Next
I hope this contribute something
Cor

Nov 20 '05 #2

P: n/a
ACK (that's me pretending to be Herfried ... I wish)

The only thing I would probably change is

Do While ... Loop

instead of what is essentially a While ... Wend loop.

Charles
"One Handed Man" <te***************************@BTOpenworld.com> wrote in
message news:ur**************@TK2MSFTNGP10.phx.gbl...
I favour the reversal code which I tend to use a lot because it's cleaner
and generally saves you getting into problems.

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.
"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
Hi,
I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever.
It started by an example from me, that was far from complete and with

typing
errors, but basically it had the meaning to show that removing controls
reversible was the nicest method.

This was a lets say conclusion (but what is that in a newsgroup) in a
discussion some weeks ago in this newsgroup. The method was contributed by Armin. I found it brilliant and since that time I call this the method
Armin.

Jack did totally disagree with this method and did after a while

contribute
some code.

Therefore I send both code's to this newsgroup in this new thread. I think it is good to talk professionally about it. So it is not the code Cor,

Nick,
Armin or Jack. Just the method "reverse For next loop", against the "While end while loop" for removing controls dynamically.

I don't want to start with my + of - points about the methods, maybe I

will
give that, but I hope that it will come automatically in this newsgroup

The code that Jack has given some contribution for me, because I did not
know "removeAT" exist. But I always do the things that I do plus in the

same
way minus. So I doubt if I will use it, but for the example I did use
"removeAT" (I think it is nicer). Please don't start a discussion about
that. The question is the "While end while" against reversal "For next".

"While end While"
Dim idx As Integer
idx = 0
While idx < Me.Panel1.Controls.Count ' while in bounds
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
Else
idx = idx + 1 ' otherwise advance to next control
End If
End While
-----------------
"For index Next reversal"
Dim idx As Integer
For idx = Me.Panel1.Controls.Count - 1 To 0 Step -1
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
End If
Next
I hope this contribute something
Cor


Nov 20 '05 #3

P: n/a
Time for my 2 pen'orth.

The first thing I need to say is that there is no right or wrong way. What
ever achieves your objective and suits your development style is right for
you.

That said, some ways of doing things tend to be better that other ways in
terms of performance, resource usage etc, but, with some of the advanced
specification of hardware these days, a few milliseconds here and there or a
few KB of menory here or there may not be your biggest concern.

The way I tend to work is to to use the power of the tools as far as I can.

Taking your first example, the problem can be demonstrated thus:

Me.Panel1.Controls
Item 0 = Label1 As Label
Item 1 = Label2 As Label
Item 2 = Label3 As Label

The first thing that is happening is that you are manually maintaing an
index counter. This is a probably performance matter compared to a loop
control variable.

On the first iteration of the loop, idx=0, Me.Panel1.Controls.Count=3 and
TypeOf Me.Panel1.Controls.Item(idx) Is Label equates to True (Label1), so
the first item is removed and the collection now comprises:

Me.Panel1.Controls
Item 0 = Label2 As Label
Item 1 = Label3 As Label

On the second iteration of the loop, idx=0, Me.Panel1.Controls.Count=2 and
TypeOf Me.Panel1.Controls.Item(idx) Is Label equates to True (Label2), so
the first item is removed and the collection now comprises:

Me.Panel1.Controls
Item 0 = Label3 As Label

On the third iteration of the loop, idx=0, Me.Panel1.Controls.Count=1 and
TypeOf Me.Panel1.Controls.Item(idx) Is Label equates to True (Label2), so
the first item is removed and the collection now comprises:

Me.Panel1.Controls

On the forth iteration of the loop, idx=0, Me.Panel1.Controls.Count=0 and so
the iteration is not executed.

Notice that idx has not been modified so the code that manually maintains
the index counter is redundant. If one if the controls wasn't a Label then
idx would have been modified but the code still had to execute the idx = idx
+ 1. (This could simplified to idx += 1).

Taking the second example, there is no manually maintained index counter -
instead, the indexing is controlled by the loop control variable. Because
the collection is being walked backwards there is no need for the idx = idx
+ 1 and, in my view the process is cleaner and 'should be' more efficient.
It could still be simplified thus:

For idx as Integer = Me.Panel1.Controls.Count - 1 To 0 Step -1
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
Next

It might be interesting, for someone who is so inclined, to compare the
resulting IL code for the 2 methodologies and see if one is more efficient
than the other or if they produce the same IL code.

Please excuse any typos or trivial coding errors.

"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
Hi,
I start a new thread about a discussion from yesterday (or for some of us
this morning). It was a not so nice discussion about dynamically removing
controls from a panel or what ever.
It started by an example from me, that was far from complete and with typing errors, but basically it had the meaning to show that removing controls
reversible was the nicest method.

This was a lets say conclusion (but what is that in a newsgroup) in a
discussion some weeks ago in this newsgroup. The method was contributed by
Armin. I found it brilliant and since that time I call this the method
Armin.

Jack did totally disagree with this method and did after a while contribute some code.

Therefore I send both code's to this newsgroup in this new thread. I think
it is good to talk professionally about it. So it is not the code Cor, Nick, Armin or Jack. Just the method "reverse For next loop", against the "While
end while loop" for removing controls dynamically.

I don't want to start with my + of - points about the methods, maybe I will give that, but I hope that it will come automatically in this newsgroup

The code that Jack has given some contribution for me, because I did not
know "removeAT" exist. But I always do the things that I do plus in the same way minus. So I doubt if I will use it, but for the example I did use
"removeAT" (I think it is nicer). Please don't start a discussion about
that. The question is the "While end while" against reversal "For next".

"While end While"
Dim idx As Integer
idx = 0
While idx < Me.Panel1.Controls.Count ' while in bounds
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
Else
idx = idx + 1 ' otherwise advance to next control
End If
End While
-----------------
"For index Next reversal"
Dim idx As Integer
For idx = Me.Panel1.Controls.Count - 1 To 0 Step -1
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
End If
Next
I hope this contribute something
Cor

Nov 20 '05 #4

P: n/a
Yes, there will probably be tiny performance differences between the two,
and when dealing with a huge collection, it might be worth looking at.

I personally prefer to see the
Dim idx as Integer = 0 before the loop, it makes it stand out more

and more inportantly.

When you traverse forward through a collection as in scenario one, its easy
to miss out that conditional increment which has bitten me a couple of times
in the past.

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.
"Stephany Young" <st******@sysoft.co.nz> wrote in message
news:%2*****************@TK2MSFTNGP11.phx.gbl...
Time for my 2 pen'orth.

The first thing I need to say is that there is no right or wrong way. What
ever achieves your objective and suits your development style is right for
you.

That said, some ways of doing things tend to be better that other ways in
terms of performance, resource usage etc, but, with some of the advanced
specification of hardware these days, a few milliseconds here and there or a few KB of menory here or there may not be your biggest concern.

The way I tend to work is to to use the power of the tools as far as I can.
Taking your first example, the problem can be demonstrated thus:

Me.Panel1.Controls
Item 0 = Label1 As Label
Item 1 = Label2 As Label
Item 2 = Label3 As Label

The first thing that is happening is that you are manually maintaing an
index counter. This is a probably performance matter compared to a loop
control variable.

On the first iteration of the loop, idx=0, Me.Panel1.Controls.Count=3 and
TypeOf Me.Panel1.Controls.Item(idx) Is Label equates to True (Label1), so
the first item is removed and the collection now comprises:

Me.Panel1.Controls
Item 0 = Label2 As Label
Item 1 = Label3 As Label

On the second iteration of the loop, idx=0, Me.Panel1.Controls.Count=2 and
TypeOf Me.Panel1.Controls.Item(idx) Is Label equates to True (Label2), so
the first item is removed and the collection now comprises:

Me.Panel1.Controls
Item 0 = Label3 As Label

On the third iteration of the loop, idx=0, Me.Panel1.Controls.Count=1 and
TypeOf Me.Panel1.Controls.Item(idx) Is Label equates to True (Label2), so
the first item is removed and the collection now comprises:

Me.Panel1.Controls

On the forth iteration of the loop, idx=0, Me.Panel1.Controls.Count=0 and so the iteration is not executed.

Notice that idx has not been modified so the code that manually maintains
the index counter is redundant. If one if the controls wasn't a Label then
idx would have been modified but the code still had to execute the idx = idx + 1. (This could simplified to idx += 1).

Taking the second example, there is no manually maintained index counter -
instead, the indexing is controlled by the loop control variable. Because
the collection is being walked backwards there is no need for the idx = idx + 1 and, in my view the process is cleaner and 'should be' more efficient.
It could still be simplified thus:

For idx as Integer = Me.Panel1.Controls.Count - 1 To 0 Step -1
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
Next

It might be interesting, for someone who is so inclined, to compare the
resulting IL code for the 2 methodologies and see if one is more efficient
than the other or if they produce the same IL code.

Please excuse any typos or trivial coding errors.

"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
Hi,
I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever.
It started by an example from me, that was far from complete and with

typing
errors, but basically it had the meaning to show that removing controls
reversible was the nicest method.

This was a lets say conclusion (but what is that in a newsgroup) in a
discussion some weeks ago in this newsgroup. The method was contributed by Armin. I found it brilliant and since that time I call this the method
Armin.

Jack did totally disagree with this method and did after a while

contribute
some code.

Therefore I send both code's to this newsgroup in this new thread. I think it is good to talk professionally about it. So it is not the code Cor,

Nick,
Armin or Jack. Just the method "reverse For next loop", against the "While end while loop" for removing controls dynamically.

I don't want to start with my + of - points about the methods, maybe I

will
give that, but I hope that it will come automatically in this newsgroup

The code that Jack has given some contribution for me, because I did not
know "removeAT" exist. But I always do the things that I do plus in the

same
way minus. So I doubt if I will use it, but for the example I did use
"removeAT" (I think it is nicer). Please don't start a discussion about
that. The question is the "While end while" against reversal "For next".

"While end While"
Dim idx As Integer
idx = 0
While idx < Me.Panel1.Controls.Count ' while in bounds
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
Else
idx = idx + 1 ' otherwise advance to next control
End If
End While
-----------------
"For index Next reversal"
Dim idx As Integer
For idx = Me.Panel1.Controls.Count - 1 To 0 Step -1
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
End If
Next
I hope this contribute something
Cor


Nov 20 '05 #5

P: n/a
Sorry, I meant

Dim idx as Integer 'before the loop, it makes it stand out more

not . .
Dim idx as Integer = 0 before the loop, it makes it stand out more
--
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.
"One Handed Man" <te***************************@BTOpenworld.com> wrote in
message news:eJ****************@tk2msftngp13.phx.gbl... Yes, there will probably be tiny performance differences between the two,
and when dealing with a huge collection, it might be worth looking at.

I personally prefer to see the
Dim idx as Integer = 0 before the loop, it makes it stand out more

and more inportantly.

When you traverse forward through a collection as in scenario one, its easy to miss out that conditional increment which has bitten me a couple of times in the past.

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.
"Stephany Young" <st******@sysoft.co.nz> wrote in message
news:%2*****************@TK2MSFTNGP11.phx.gbl...
Time for my 2 pen'orth.

The first thing I need to say is that there is no right or wrong way. What
ever achieves your objective and suits your development style is right for you.

That said, some ways of doing things tend to be better that other ways in terms of performance, resource usage etc, but, with some of the advanced
specification of hardware these days, a few milliseconds here and there or
a
few KB of menory here or there may not be your biggest concern.

The way I tend to work is to to use the power of the tools as far as I can.

Taking your first example, the problem can be demonstrated thus:

Me.Panel1.Controls
Item 0 = Label1 As Label
Item 1 = Label2 As Label
Item 2 = Label3 As Label

The first thing that is happening is that you are manually maintaing an
index counter. This is a probably performance matter compared to a loop
control variable.

On the first iteration of the loop, idx=0, Me.Panel1.Controls.Count=3

and TypeOf Me.Panel1.Controls.Item(idx) Is Label equates to True (Label1), so the first item is removed and the collection now comprises:

Me.Panel1.Controls
Item 0 = Label2 As Label
Item 1 = Label3 As Label

On the second iteration of the loop, idx=0, Me.Panel1.Controls.Count=2 and TypeOf Me.Panel1.Controls.Item(idx) Is Label equates to True (Label2), so the first item is removed and the collection now comprises:

Me.Panel1.Controls
Item 0 = Label3 As Label

On the third iteration of the loop, idx=0, Me.Panel1.Controls.Count=1 and TypeOf Me.Panel1.Controls.Item(idx) Is Label equates to True (Label2), so the first item is removed and the collection now comprises:

Me.Panel1.Controls

On the forth iteration of the loop, idx=0, Me.Panel1.Controls.Count=0 and so
the iteration is not executed.

Notice that idx has not been modified so the code that manually
maintains the index counter is redundant. If one if the controls wasn't a Label then idx would have been modified but the code still had to execute the idx =

idx
+ 1. (This could simplified to idx += 1).

Taking the second example, there is no manually maintained index counter - instead, the indexing is controlled by the loop control variable. Because the collection is being walked backwards there is no need for the idx =

idx
+ 1 and, in my view the process is cleaner and 'should be' more efficient. It could still be simplified thus:

For idx as Integer = Me.Panel1.Controls.Count - 1 To 0 Step -1
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
Next

It might be interesting, for someone who is so inclined, to compare the
resulting IL code for the 2 methodologies and see if one is more efficient than the other or if they produce the same IL code.

Please excuse any typos or trivial coding errors.

"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
Hi,
I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever.
It started by an example from me, that was far from complete and with

typing
errors, but basically it had the meaning to show that removing controls reversible was the nicest method.

This was a lets say conclusion (but what is that in a newsgroup) in a
discussion some weeks ago in this newsgroup. The method was contributed by
Armin. I found it brilliant and since that time I call this the method
Armin.

Jack did totally disagree with this method and did after a while

contribute
some code.

Therefore I send both code's to this newsgroup in this new thread. I think it is good to talk professionally about it. So it is not the code Cor,

Nick,
Armin or Jack. Just the method "reverse For next loop", against the "While end while loop" for removing controls dynamically.

I don't want to start with my + of - points about the methods, maybe I

will
give that, but I hope that it will come automatically in this

newsgroup
The code that Jack has given some contribution for me, because I did not know "removeAT" exist. But I always do the things that I do plus in the same
way minus. So I doubt if I will use it, but for the example I did use
"removeAT" (I think it is nicer). Please don't start a discussion

about that. The question is the "While end while" against reversal "For next".
"While end While"
Dim idx As Integer
idx = 0
While idx < Me.Panel1.Controls.Count ' while in bounds
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
Else
idx = idx + 1 ' otherwise advance to next control
End If
End While
-----------------
"For index Next reversal"
Dim idx As Integer
For idx = Me.Panel1.Controls.Count - 1 To 0 Step -1
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
End If
Next
I hope this contribute something
Cor



Nov 20 '05 #6

P: n/a
Nak
Hi Cor,

http://members.lycos.co.uk/nickpatemanpwp/mynews.htm

I uploaded a quick test of all 3 methods onto my web site, read the top item
on my news page for the download link. It's a tiny file and the tests just
go to show that there is practically nothing in it what so ever.

The test works by adding a user defined number of controls to a panel
(currently @ 10,000), these controls are randomly chosen to be either a
button or a label. The 3 routines then test removing only the label
controls and give a result in (ms), on my computer the results were,

While method = 9937ms
For method (reverese removal) = 9984
For method (my crappy forward removal method) = 9781

Nothing in it what so ever, so it's just a matter of personal preference and
ease of typing isn't it?

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #7

P: n/a
Cor
Hi Nick,
Thanks,
As I promished I give no comments now except.
I measured while 15.453, for, 15.390, cr 15.281
But those slight differences say nothing because it is not a total clean
Computer (there are interupts).
Cor

Nov 20 '05 #8

P: n/a
Nak
> As I promished I give no comments now except.
I measured while 15.453, for, 15.390, cr 15.281
But those slight differences say nothing because it is not a total clean
Computer (there are interupts).
Cor


Hi Cor,

Agreed, the test isn't "clean" as such, but is a test ever clean on a
system with Windows running? It just goes to show how little is in it,
other than programming preference :-)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #9

P: n/a
What the *&^% is this all about, a few milliseconds.
I agree with Nak, its down to personal preference

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.
"Nak" <a@a.com> wrote in message
news:OP**************@tk2msftngp13.phx.gbl...
As I promished I give no comments now except.
I measured while 15.453, for, 15.390, cr 15.281
But those slight differences say nothing because it is not a total clean
Computer (there are interupts).
Cor
Hi Cor,

Agreed, the test isn't "clean" as such, but is a test ever clean on a
system with Windows running? It just goes to show how little is in it,
other than programming preference :-)

Nick.

--

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ "No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

Nov 20 '05 #10

P: n/a
Hi Stephanie,

Unfortunately, for me with v2002,
For I As Integer = ...
gives a syntax error. Glad it's been added to v2003.
I agree that:

For idx as Integer = Me.Panel1.Controls.Count - 1 To 0 Step -1
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
Next

is shorter, but to me it <looks> more complicated than with the If spread
out to three lines.

Regards,
Fergus
Nov 20 '05 #11

P: n/a
Hi Cor,

I prefer the For loop because it is simpler and shorter on the page.

Simpler for someone trying to understand it:

Correctness
With the For loop you need to ensure that it does
the correct thing in the If.

With the While you have to ensure that it does the
correct thing on both branches of the If.

Progression
The For loop <always>
decrements which makes it straghtforward.

You have to realise that it doesn't always increment,
and be happy that that makes sense.

Imagery
The imagery with the For loop is of going backwards
down a list saying either "You're ok" or "You - out" and
the line shuffling down to close the gap.

The imagery with the While is of going intermittently
forwards up a list saying either "You - stay" and moving
past, or "You - out. Next!" and the line shuffling up to
meet you.

As with the performance issue, the difference is marginal. :-)

For me the overriding consideration is that it takes fewer lines.Lines on the screen, to me, is one hell of a valuable
commodity.

Regards,
Fergus
Nov 20 '05 #12

P: n/a
"Charles Law" <bl**@thingummy.com> schrieb:
ACK (that's me pretending to be Herfried ... I wish)

The only thing I would probably change is

Do While ... Loop

instead of what is essentially a While ... Wend loop.


A 'While...End While' loop.

;-)

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

P: n/a
I didn't mistype it, but hasn't Wend only just been finally banished from
the language? Or did I just dream it!

Charles
[How do I do raised eyebrows, quizzical look? ):-[] maybe? If I have just
indicated something rude or offensive with my attempt, please ignore]
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:OG**************@TK2MSFTNGP10.phx.gbl...
"Charles Law" <bl**@thingummy.com> schrieb:
ACK (that's me pretending to be Herfried ... I wish)

The only thing I would probably change is

Do While ... Loop

instead of what is essentially a While ... Wend loop.


A 'While...End While' loop.

;-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #14

P: n/a
Cor
Herfried,
I asume this is not your contribution after all you did write last night.
I expect that Tom, Jeremy and Jay B do that for us when it is for us night
(Or is Tom too Europe?).
I think, this is more important than 6 man(3 MVP) who give answers how to
add a preceding zero to a string.
(Sorry but I had to laugh when I saw that)

After doing this the people active in this newsgroup can give an uniform
answer and we have again less so long useless threads anymore.

The only one who I can imaging who gives not comments is Armin, his idea it
obvious.
I and I think others too are curious to the ideas of you and the other
MVP's.

Cor
Nov 20 '05 #15

P: n/a
Cor
Charles,
I thought that too, but because of the discussion last night I did not want
to contribute that, lets do if the
while end loop is the same as the do while loop.
OK?
Cor
Nov 20 '05 #16

P: n/a
Cor
Charles
The reversal is the for index and not the Do While
I do not understand you.
when you say
ACK (that's me pretending to be Herfried ... I wish)

The only thing I would probably change is

Do While ... Loop

instead of what is essentially a While ... Wend loop.

Charles

Nov 20 '05 #17

P: n/a
Cor
Hi Nick
The test is very good to make the discussion beter I think Nick

I try to give no comments, makes evaluating much easier.

I keep doing it on my own way and you too.
But it is good for thinking it over.
Cor
Nov 20 '05 #18

P: n/a
I think you'll find he was referring to the first example.

"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
Charles
The reversal is the for index and not the Do While
I do not understand you.
when you say
ACK (that's me pretending to be Herfried ... I wish)

The only thing I would probably change is

Do While ... Loop

instead of what is essentially a While ... Wend loop.

Charles


Nov 20 '05 #19

P: n/a
"Cor" <no*@non.com> schrieb:
I asume this is not your contribution after all you did
write last night.
???
I expect that Tom, Jeremy and Jay B do that for us when
it is for us night (Or is Tom too Europe?).
What? I do not really understand what you mean.
I think, this is more important than 6 man(3 MVP) who give
answers how to add a preceding zero to a string.
(Sorry but I had to laugh when I saw that)
I had to laugh too.
After doing this the people active in this newsgroup can
give an uniform answer and we have again less so long
useless threads anymore.
I don't understand what you mean.
The only one who I can imaging who gives not comments
is Armin, his idea it obvious.
I and I think others too are curious to the ideas of you and
the other MVP's.


???

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

P: n/a
"Charles Law" <bl**@thingummy.com> schrieb:
I didn't mistype it, but hasn't Wend only just been finally
banished from the language? Or did I just dream it!


'Wend' doesn't exist any more.

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

P: n/a
"Cor" <no*@non.com> schrieb:
I thought that too, but because of the discussion last night I did
not want to contribute that, lets do if the while end loop is
the same as the do while loop.


???

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #22

P: n/a
Cor,
I expect that Tom, Jeremy and Jay B do that for us when it is for us night Huh? someone talking about me??
After doing this the people active in this newsgroup can give an uniform
answer and ... My concern is there is no 'uniform' answer! As there are multiple ways of
doing the same thing, equally correct. If only one of us, gives a single
'uniform' answer, then we did not give all the options. Depending on the
situation, one of the other options may be the better solution.
... we have again less so long useless threads anymore. I try to avoid 'long useless threads'. If I feel I am communicating (two
way) an idea with someone & that idea may be beneficial for others I will
continue the thread (Richard & user controls come to mind). However if it
starts appearing that one of us is not getting what the other is saying, I
will 'drop the issue'. Or the discussion is largely "Oh Yea! mines bigger"
I think, this is more important than 6 man(3 MVP) who give answers how to
add a preceding zero to a string. However they where 6 distinct equally correct answers! :-)

Even if we all gave the same 6 answers, as Herfried has stated before, its a
matter of timing. I don't know if the other 5 are currently on, answering a
question, they one of them is happening to hit send at the same micron that
I am. Its impractically for us to communicate with each other that one of us
has it, there are just too many questions. Most of the MVPs I know have full
time jobs, in addition to answering questions. Plus they author books.

Just a thought
Jay

"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl... Herfried,
I asume this is not your contribution after all you did write last night.
I expect that Tom, Jeremy and Jay B do that for us when it is for us night
(Or is Tom too Europe?).
I think, this is more important than 6 man(3 MVP) who give answers how to
add a preceding zero to a string.
(Sorry but I had to laugh when I saw that)

After doing this the people active in this newsgroup can give an uniform
answer and we have again less so long useless threads anymore.

The only one who I can imaging who gives not comments is Armin, his idea it obvious.
I and I think others too are curious to the ideas of you and the other
MVP's.

Cor

Nov 20 '05 #23

P: n/a
Cor
Jay,
That is an answer,
This is not a matter of what is good or bad, no meaning about it, is too a
meaning.
But I think that it is not good for a newsgroup when there are messages who
says: "I think that is basicly not good".
And I have seen a lot about this subject.
Tell why or don't write those messages.
It is the same as when I say I don't like beans.

Because you are an important contributer to this group, and did give your
idea's in a discussion I mean a week ago, I thought it was good if you did
contribute to this discussion too.
Nick did some work to make a test, I thought because some people say we must
measure that.

But if you have no meaning.
That is a meaning too.

Cor.
Nov 20 '05 #24

P: n/a
Cor
Herfried,
Just an opinion.
If you want to know my opinion that is the same as mid, instr, substring,
indexoff + & (not for uper an lowercase and ==) etc.
But if you can tell why you find one methodiek better than the other, that
would be too a contribution.
And if you want to illustrate that with a hyperlink too no problem.
But I have seen yesterday many ACK in your post when this was the subject.
And that has nothing personal for me.
This subject or the late night ACK's changes nothing in my thinking about
you.
And if you don't want to do that, too no problem, but write that, I do want
to try to make a evaluation on about sunday.
Cor
Nov 20 '05 #25

P: n/a
With you all the way Cor.

Charles
"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
Charles,
I thought that too, but because of the discussion last night I did not want to contribute that, lets do if the
while end loop is the same as the do while loop.
OK?
Cor

Nov 20 '05 #26

P: n/a
Hi Cor

It's just that I often see Herfried say "ACK" when he agrees with something.
The guy's obviously got a brain the size of a planet, so I can only aspire
to the breadth of his knowledge. Even if I did know all the stuff he knows,
I could never recall it all so quickly, and post links to relevant info all
the time.

Charles
"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
Charles
The reversal is the for index and not the Do While
I do not understand you.
when you say
ACK (that's me pretending to be Herfried ... I wish)

The only thing I would probably change is

Do While ... Loop

instead of what is essentially a While ... Wend loop.

Charles


Nov 20 '05 #27

P: n/a
Hi Herfried

I don't think we are in disagreement. It's just my way of writing I think.

Charles
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
"Charles Law" <bl**@thingummy.com> schrieb:
I didn't mistype it, but hasn't Wend only just been finally
banished from the language? Or did I just dream it!


'Wend' doesn't exist any more.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #28

P: n/a
Cor
He is young, when I was that age I could that too in a way, now I have to
say, for me it is the same as you Charles.
:-)
Nov 20 '05 #29

P: n/a
Hi Cor, Charles,

It also helps to have an installed copy of the Herfried Handy Hypertext Help system - 10 gigabytes of links searchable via a
Brain-to-PC interface (USB 2, I believe). :-)

Regards,
Fergus
Nov 20 '05 #30

P: n/a
Hello, group:

I think you are building a planet from a grain of sand.
I'd prefer to give my contribution code working and tested, but I can't wait until tomorrow to write it on the computer in wich I have .NET installed. I hope you understand my intention and forgive the errors:

sub DeleteTextBoxes()
dim ctllist as Collection
dim ctl as control

for each ctl in me.controls
if typeof(ctl) is textbox then
ctllist.add ctl
end if
next

for each ctl in ctllist
me.controls.remove(ctl)
'Other cleaning stuff...
next

ctllist.clear 'Deletes the last reference to textboxes (unnecesary because ctllist stops existing when the sub ends).
end sub

I hope this works (and you like it)

Regards.
"Cor" <no*@non.com> escribió en el mensaje news:3f***********************@reader20.wxs.nl...
| Hi,
| I start a new thread about a discussion from yesterday (or for some of us
| this morning). It was a not so nice discussion about dynamically removing
| controls from a panel or what ever.
| It started by an example from me, that was far from complete and with typing
| errors, but basically it had the meaning to show that removing controls
| reversible was the nicest method.
|
| This was a lets say conclusion (but what is that in a newsgroup) in a
| discussion some weeks ago in this newsgroup. The method was contributed by
| Armin. I found it brilliant and since that time I call this the method
| Armin.
|
| Jack did totally disagree with this method and did after a while contribute
| some code.
|
| Therefore I send both code's to this newsgroup in this new thread. I think
| it is good to talk professionally about it. So it is not the code Cor, Nick,
| Armin or Jack. Just the method "reverse For next loop", against the "While
| end while loop" for removing controls dynamically.
|
| I don't want to start with my + of - points about the methods, maybe I will
| give that, but I hope that it will come automatically in this newsgroup
|
| The code that Jack has given some contribution for me, because I did not
| know "removeAT" exist. But I always do the things that I do plus in the same
| way minus. So I doubt if I will use it, but for the example I did use
| "removeAT" (I think it is nicer). Please don't start a discussion about
| that. The question is the "While end while" against reversal "For next".
|
| "While end While"
| Dim idx As Integer
| idx = 0
| While idx < Me.Panel1.Controls.Count ' while in bounds
| If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
| Me.Panel1.Controls.RemoveAt(idx)
| Else
| idx = idx + 1 ' otherwise advance to next control
| End If
| End While
| -----------------
| "For index Next reversal"
| Dim idx As Integer
| For idx = Me.Panel1.Controls.Count - 1 To 0 Step -1
| If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
| Me.Panel1.Controls.RemoveAt(idx)
| End If
| Next
| I hope this contribute something
| Cor
|
|
|
|
Nov 20 '05 #31

P: n/a
Hi Jose,

But it's a hell of a great planet!!

I've seen your method before. It is very unambiguous and there are no worries about whether you are tripping over your own tail.
First you collect. Then you remove. Simple.

But, as I mentioned in my post above, screen space is very important, so, for me, it is too long.

However, welcome to the debate. :-)

Regards,
Fergus
Nov 20 '05 #32

P: n/a
Hello,

"Cor" <no*@non.com> schrieb:
He is young, when I was that age I could that too in a way, now I have to
say, for me it is the same as you Charles.


;-)

When you were young, there was probably no .NET framework available.

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

P: n/a
Hello,

"Fergus Cooney" <fi******@tesco.net> schrieb:
But it's a hell of a great planet!!

I've seen your method before. It is very unambiguous and there
are no worries about whether you are tripping over your own tail.
First you collect. Then you remove. Simple.

But, as I mentioned in my post above, screen space is very important,
so, for me, it is too long.


Encapsulate it...

;-)))

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

P: n/a
Hello,

"Charles Law" <bl**@thingummy.com> schrieb:
I don't think we are in disagreement. It's just my way of writing I think.


That's what I think too.

:-)

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

P: n/a
Cor
Haha. I have a sent folder with 20,000 postings I wrote in the past. A
lot
of questions can be answered by querying this folder. And: I use Google
Groups Search and the MSDN documentation. For some unknown reason, most
people do not have a look at the docs before asking a question.

I was thinking about that Yesterday when I did read the message from
Charles,
I had always said, in this bussiness it't not important to know, just to
know where it is written.
And then I thought how would that be with Herfried, but you did send the
answer.

I did make that folder too last week.
A lot of Herfried, Jay B and now Fergus is in it.
The last one was a letter M.
The other things I can remember.
:-)
Cor
Nov 20 '05 #36

P: n/a
Cor
Herfried,
That is an answer,
:-)
Cor
Nov 20 '05 #37

P: n/a
Nak
> When you were young, there was probably no .NET framework available.

Were there computers then? I thought people used the abacus? ;-)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #38

P: n/a
Cor
That was not yet invented only fingers and tones
Nov 20 '05 #39

P: n/a
Nak
> That was not yet invented only fingers and tones

LOL, like "Ug!" ? ;-)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #40

P: n/a
Hi Cor,

|| The last one was a letter M.

Lol.

Regards,
Fergus
Nov 20 '05 #41

P: n/a
ROFL
Nov 20 '05 #42

P: n/a
Hello:

Really I haven't read a book about programming since I started programming the PC (it was a manual for VB3). I have only read the help provided by Microsoft with posterior releases of VB.

So I'm quite lost (apart from my bad English) when you say things in this context like "screen space is very important" and "Encapsulate it" :'-(

Well, you're really building a great planet of knowledge in this newsgroup and I will take as much advantage of it as I can :-)

Regards.

P.S. Is there any native English-speaking people here? I'm Spanish and I know many of you are not English... ;-)

Regards again.
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> escribió en el mensaje news:eS**************@TK2MSFTNGP09.phx.gbl...
| Hello,
|
| "Fergus Cooney" <fi******@tesco.net> schrieb:
| > But it's a hell of a great planet!!
| >
| > I've seen your method before. It is very unambiguous and there
| > are no worries about whether you are tripping over your own tail.
| > First you collect. Then you remove. Simple.
| >
| > But, as I mentioned in my post above, screen space is very important,
| > so, for me, it is too long.
|
| Encapsulate it...
|
| ;-)))
|
| --
| Herfried K. Wagner
| MVP · VB Classic, VB.NET
| http://www.mvps.org/dotnet
|
|
Nov 20 '05 #43

P: n/a
Hi Jose,

I'm a Londoner. You'll get correct English from me and also slang. Naa wot ar mean, like?*

|| "screen space is very important"

By this I mean that I like my code to be as compact as possible so that I can see as much as possible on the screen. That's one
of the reasons that I like C# compared to VB.NET.

C#
public int Foo { get { return m_Foo; } set { m_Foo = (value <= 0) ? 1 : value; }}

vs
Public Property Foo As Integer
Get
Return m_Foo
End Get
Set
m_Foo = IIf (Value <= 0, 1, Value)
End Set
End Property

One line versus 8!!

|| "Encapsulate it"

Herfried is saying. Don't worry about the length - write it as a routine in a a module, eg ControlsLib.RemoveControls
(Collection, Type), and call it. That'll bring it down to a single line it the calling code. And there'll be another useful utility
in the Controls library.

Regards,
Fergus
*
"Naa wot ar mean, like?"
Similar: Get me drift?
Meaning: Does this make sense?
Literally, formally - Do you understand what I mean?

:-)
Nov 20 '05 #44

P: n/a
Hi, Fergus:

Thanks for the explanation.

:-)

Regards
"Fergus Cooney" <fi******@tesco.net> escribió en el mensaje news:%2****************@TK2MSFTNGP09.phx.gbl...
| Hi Jose,
|
| I'm a Londoner. You'll get correct English from me and also slang. Naa wot ar mean, like?*
|
| || "screen space is very important"
|
| By this I mean that I like my code to be as compact as possible so that I can see as much as possible on the screen. That's one
| of the reasons that I like C# compared to VB.NET.
|
| C#
| public int Foo { get { return m_Foo; } set { m_Foo = (value <= 0) ? 1 : value; }}
|
| vs
| Public Property Foo As Integer
| Get
| Return m_Foo
| End Get
| Set
| m_Foo = IIf (Value <= 0, 1, Value)
| End Set
| End Property
|
| One line versus 8!!
|
| || "Encapsulate it"
|
| Herfried is saying. Don't worry about the length - write it as a routine in a a module, eg ControlsLib.RemoveControls
| (Collection, Type), and call it. That'll bring it down to a single line it the calling code. And there'll be another useful utility
| in the Controls library.
|
| Regards,
| Fergus
| *
| "Naa wot ar mean, like?"
| Similar: Get me drift?
| Meaning: Does this make sense?
| Literally, formally - Do you understand what I mean?
|
| :-)
|
|
Nov 20 '05 #45

P: n/a
Hello,

"Cor" <no*@non.com> schrieb:
Haha. I have a sent folder with 20,000 postings I wrote
in the past. A lot of questions can be answered by querying
this folder. And: I use Google Groups Search and the MSDN
documentation. For some unknown reason, most
people do not have a look at the docs before asking a question.
I was thinking about that Yesterday when I did read the message from
Charles, I had always said, in this bussiness it't not important to
know, just to know where it is written.


I fully agree.
And then I thought how would that be with Herfried, but you did send the
answer.

I did make that folder too last week.
A lot of Herfried, Jay B and now Fergus is in it.
The last one was a letter M.
The other things I can remember.


Notice that you can query "all" messages of this ng by using Google Groups
Search.

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

P: n/a
Hello,

"Cor" <no*@non.com> schrieb:
That is an answer,
:-)


Now I am back, but there are hundreds of unanswered messages waiting for
me...

;-)

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

P: n/a
Hello,

"Nak" <a@a.com> schrieb:
When you were young, there was probably no .NET
framework available.


Were there computers then? I thought people used the
abacus? ;-)


No, but Commodore or Amiga knowledge doesn't help answering questions in
this ng.

;-)

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

P: n/a
Hello,

"José Manuel Agüero" <jm******@vodafone.es> schrieb:
So I'm quite lost (apart from my bad English)
Huh. My English is very bad...
when you say things in this context like "screen space is very
important" and "Encapsulate it" :'-(
I wanted to tell you that you write a little procedure that "encapsulates"
the routine and makes it reusable. You don't need to worry about the
implementation every time you use the procedure.
P.S. Is there any native English-speaking people here? I'm Spanish
and I know many of you are not English... ;-)


I live in Austria.

:-)

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

P: n/a
;-)
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> escribió en el mensaje news:ef**************@TK2MSFTNGP11.phx.gbl...
|
| I live in Austria.
|
| :-)
|
| --
| Herfried K. Wagner
| MVP · VB Classic, VB.NET
| http://www.mvps.org/dotnet

Nov 20 '05 #50

66 Replies

This discussion thread is closed

Replies have been disabled for this discussion.