473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Serious discussion about removing dynamically controls

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
66 4041
Nak
> No, but Commodore or Amiga knowledge doesn't help answering questions in
this ng.


If I were critical, I would say that any computer knowledge helps in any
computer related newsgroup, BTW Amiga's were made by Commodore. :-)

Nick.

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

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #51
Cor
Nick,
I am quiet sure that Commodore is now owned by Tulip.

I think that when you are talking about the time Amiga was building
Commodore that where the homecomputers then.

Before that time I thought that what was Commodore as a homecomputer in
Germany, was Amiga in England.

(About the last things I am not sure, I never used or had either one of
them)

Cor
Nov 20 '05 #52
Hi Cor

The reason that I expressed a preference for the Do While ... Loop method
comes from its simpler form:

<this is not intended to execute ;-)>
Do While Collection.Count > 0
Collection.RemoveAt(0)
Loop
</this is not intended to execute ;-)>

which clearly removes every element from the collection. I like it because
it is short and sweet. Conversely, I have this aversion to using For ...
Next loops where I modify the loop control variable within the loop. It
frightens me.

I realise though, that my example above is in danger of locking if the
RemoveAt(0) fails for any reason, so some form of hat is probably in order.

Regards

Charles
"Cor" <no*@non.com> wrote in message
news:3f***********************@reader22.wxs.nl...
Hi,
I'll try to "encapsulate" (please don't shoot) the short discussion.

Nick did make a test program and the result was:
That if you use a "for next loop", or a "do while loop", or with a "crappie method" or with a good other method, the process time is almost the same.

Most of the writers are saying after that they had seen the measurement from Nick, "Do it your own way?

The ones who prefer the reversal "for next" method do that because of the
compactness of the code. The ones who prefer the "do while loop" did not
tell why, maybe it just because they are used to do it that way.

For me it is clear, I will use the "for next" loop in this situation because the compactness. And what others say, I gladly follow the words of Jay B.:
"My concern is there is no 'uniform' answer! As there are multiple ways of
doing the same thing, equally correct."

Cor


Nov 20 '05 #53
Cor
Charles,
The do while loop and removing controls(0) goes wrong if some controls have
to stay on the parent control.
The counter comes never to zero and becomes a loop.

That is the nicest thing of the reverse for next

Therefore has the methode from Jack an index and does Jose first collect the
controls that have to be removed.

With both those methodes (I did not evaluate the methode from Nick) is in my
opinion nothing wrong.

The reversal for next which Armin did introduce to me is for me the most
compact to write and most easy to read for others.
When you see it, you understand immidiatly what happens.

When there is not the problem from controls that maybe stay on the parent
control then I choose the code you suggest.

Cor
Nov 20 '05 #54
Hello:

Thanks, Cor. I hadn't understood completely the discussion, because of my lack of experience in this groups (apart from the difficulty of speaking in English), I suppose.

I included that code because the first time I used "For Each" loops was with the FileSystemObject to rename files in a folder: the result was that sometimes the files that had changed the name appeared later in the same loop (but not always!), so I started using the method "first collect, then modify".

In respect to the "real" discussion of this thread I prefer explicit code rather than compact: I used compact code when programming my old Amstrad with a Z80, but after some years I prefer clear structures with a declared start and end ("Sub...End Sub" instead of "Proc(){...}"): that's why I don't like C: you end up with a lot of consecutive "}".
There is an example in other thread with one line like this (E is a structure):
E e3=(E) 3
and I prefer:
Dim e3 as E=E.3
I think its much clearer.
I apply the same for different methods of doing the same thing in VB: I always select the clearest one, not the fastest (if speed is not fundamental) nor the "prettiest", nor the most compact.

Well, that's my opinion, after so much posts...

;-) Regards.
"Cor" <no*@non.com> escribió en el mensaje news:3f***********************@reader22.wxs.nl...
| Hi,
| I'll try to "encapsulate" (please don't shoot) the short discussion.
|
| Nick did make a test program and the result was:
| That if you use a "for next loop", or a "do while loop", or with a "crappie
| method" or with a good other method, the process time is almost the same.
|
| Most of the writers are saying after that they had seen the measurement from
| Nick, "Do it your own way?
|
| The ones who prefer the reversal "for next" method do that because of the
| compactness of the code. The ones who prefer the "do while loop" did not
| tell why, maybe it just because they are used to do it that way.
|
| For me it is clear, I will use the "for next" loop in this situation because
| the compactness. And what others say, I gladly follow the words of Jay B.:
| "My concern is there is no 'uniform' answer! As there are multiple ways of
| doing the same thing, equally correct."
|
| Cor
|
|
|
|
|
Nov 20 '05 #55
Hi Jose,

|| E e3=(E) 3

Eee bah goom! will you look at that!!.

Regards,
Fergus
Nov 20 '05 #56
Sorry, British humour :-D
Nov 20 '05 #57
Nak
> Before that time I thought that what was Commodore as a homecomputer in
Germany, was Amiga in England.


Hi Cor,

Commodore have made many computers, not just Amiga, and we had others
here in England too, Commodore 64 for example. I *thought* that Amiga was a
'subsidiary' (I think I spelt that right) of Commodore, when Amiga went bust
Gateway bought them from Commodore. I *knew* someone who was in development
of a game engine the time that Amiga went bust, tis a shame :-D. You can
still get very good Amiga emulators for PC, http://www.winuae.net/. I hate
Gateway....

Nick.

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

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #58
Nak
> Sorry, British humour :-D

Nout wrong with that! When I were a lad I used to tie two slices of 'ovis
to mah feet, and if it were icy, i'd toast em for t' extra grip!

Nick.

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

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

Morning Nick.
Except I'm off to bed.
Nov 20 '05 #60
Nak
> Morning Nick.
Except I'm off to bed.


Morning Fergus, late night by any chance? ;-) I know a cure for that, stop
downloading "rare material" mate you might have more hours in the day ;-)
;-)

Nick.

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

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #61
Hi Nick,

I've been waiting days and weeks, just getting little trickles (of <data>
not what <you're> thinking!!), but I was always waiting in the queue. Last
night I said To Hell with them and switched off uploads. Wow. 140MB.

Regards,
Fergus

It <is> music. [sob] It really <is> music. [small voice: nobody believes me,
sob]
Nov 20 '05 #62
Hello,

"Fergus Cooney" <fi******@tesco.net> schrieb:
To Hell with them and switched off uploads. Wow. 140MB.

140 MB of postings on a single day... Really good.

;-)

--
Herfried K. Wagner
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 20 '05 #63
Nak
> I've been waiting days and weeks, just getting little trickles (of
<data>
not what <you're> thinking!!), but I was always waiting in the queue. Last night I said To Hell with them and switched off uploads. Wow. 140MB.


I presume that you are referring to Shareaza? What a load of toot that is,
I absolutly love the program, it's an excellent piece of software, lovely to
look at too, but downloads can take days!! You end up something like number
5643 in someones que, and the program makes such a large number of
connections that it periodically knocks my router out, which is nice :-)
But yes, I believe you, music it is, rare music, like Des O'Connor maybe?

Nick.

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

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #64
Hi Nick.

|| But yes, I believe you, music it is, rare music, like Des O'Connor
maybe?

Wierdly enough, it's not what I'd have called rare. But there is just a
single source for much of what I want.
|| Shareaza .. but downloads can take days ..
|| such a large number of connections ..

That's what I've found - all these connections. I'd be watching a
download. It would grab maybe 64K then drop the connection and starts its
little countdown again. I'm sitting there shouting at it - "Go on, You just
<had> it. Go get it!!". Naturally it ignores me until I do <Right-Click>
Access. Then off it goes for aonther dribble. Honestly - File sharers these
days, you can't take your eyes off them for a moment the lazy so-and-so's.

The forums say "Oh, you've got to be patient, got to build up your
'credit' by uploading". Grrr. I'm giving out megabytes per hour just to get
one 5 minute track per night!!

Anyway yesterday I got really fed up with it. I opened the System window
to watch what was happening to my download slots - why were they so brief and
unstable. I couldn't see what was going on because of all the in-and-out
rubbish. So I hit the disconnect button. Being already in touch with my
source, I figured that I didn't need to be connected. [It works that way with
Kazaa when it can't connect - previous downloads carry on regardless]. Well
this didn't change that much until my ISP cut me off. On redialing, I got a
new IP and so the network didn't know about me. All the traffic dropped to
nothing. The uploading stopped once my queues emptied and my download speed
went straight to MAX!!! It's against the spirit of things but I figure I've
done well over my fair share.

It may work for you. I reckon you only need the network aspect for
searching and finding more sources. I prefer it without more sources. I have a
C# manual 'on order' with > 400 sources. Not one of them is willing to give it
up. And Shareaza is a bit stupid in many little ways - I'm in my own source
list several times over!!

Regards,
Fergus
Nov 20 '05 #65
Nak
Hi Fergus,
|| But yes, I believe you, music it is, rare music, like Des O'Connor
maybe?
As I suspected...
That's what I've found - all these connections. I'd be watching a
download. It would grab maybe 64K then drop the connection and starts its
little countdown again. I'm sitting there shouting at it - "Go on, You just <had> it. Go get it!!". Naturally it ignores me until I do <Right-Click>
Access. Then off it goes for aonther dribble. Honestly - File sharers these days, you can't take your eyes off them for a moment the lazy so-and-so's.
Yeah, so right, I even feel that if I look at the damn thing it actually
stops. It's strange, with Shareaza I can have something downloading at 1
KB/S and the damn thing has made well in excess of 100 connections!!, then
it stops downloading just because it can. Lazy? they are *ucking useless
half the time!
The forums say "Oh, you've got to be patient, got to build up your
'credit' by uploading". Grrr. I'm giving out megabytes per hour just to get one 5 minute track per night!!
Haha, I saw a tweak somewhere that got the application to upload files
to yourself over and over again, increasing your 'credit' by yourself so to
speak. Have you tried Kazaa Lite? http://www.kazaalitekpp.com/ No spyware,
download 'acceleration' etc, just a pitty there is no error checking like
with Shareaza, because you could download a 700mb zip file simply for it to
contain 1 CRC error and you're buggered! :-(
It may work for you. I reckon you only need the network aspect for
searching and finding more sources. I prefer it without more sources. I have a C# manual 'on order' with > 400 sources. Not one of them is willing to give it up. And Shareaza is a bit stupid in many little ways - I'm in my own source list several times over!!


Haha, I got some VB.NET 'manuals' but I don't want to print them off,
have you tried reading a book in the form of a reem of unbinded paper? It's
not pleasent. Pah, Shareaza, such a silly program at times, it doesn't do
itself any justice, like when is the guy going to give information on making
plugins for it? He only needs to release a simple example plugin!! maybe
they are hard coded! ;-)

Nick.

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

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #66
Hi Nick,

|| I even feel that if I look at the damn thing it actually stops.

Lol.

|| downloading at 1 KB/S and the damn thing has made well
|| in excess of 100 connections

Disconnect. When you've got a download happening and want it good, it's
worth a try.

|| Kazaa .. download a 700mb zip file simply for it to
|| contain 1 CRC error and you're buggered!

700mb? You've obviously got more than a 2KB modem. :-) Alright for some!!

My biggest failure was a 14MB chm file. It arrived and showed the table of
contents. A hex dump showed that it was stuffed full of pages. But it wouldn't
display a single page!

|| reading a book in the form of a reem of unbinded paper

I have a friend who used to work at Zerox. He'd come round and present me
with that ream of paper - rephotocopied from single-sided to double-sided,
sorted, bound and covered. A friend in the land of the copier!! Alas, he's not
there any more. But that's because he's moved to **??** where they have a
whole different set of goodies!! ;-)

Regards,
Nick.
Nov 20 '05 #67

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
0
by: sameer mowade via .NET 247 | last post by:
Hello All, I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically...
7
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web...
11
by: Andy Chan | last post by:
First of all, thanks to Crirus and Fergus for helping me with a related posted a few days ago. Ok, I can add images to my form (for whatever reason I cannot added more than 1 image within the...
1
by: mazdotnet | last post by:
Hi, I have a user control that I add dynamically. Once certain action is performed I want to remove it completely. My questions are 1. How do you check to see if a user control already exists...
4
by: =?Utf-8?B?T2xhbg==?= | last post by:
Hi, I'm trying to dynamically remove labels from a windows form in csharp. I have a foreach loop similar to : foreach(Control c in this.Controls) { c.Dispose(); }
2
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have the following code the dynamically adds a specific number of controls. for x as integer = 1 to 10 Dim btn as Windows.Forms.Button = New Windows.Forms.Button btn.Name = "btn" & x btn.Text...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.