Click here to Skip to main content
15,914,924 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionNetwork question (beginner) Pin
Derek G28-Dec-05 5:58
Derek G28-Dec-05 5:58 
AnswerRe: Network question (beginner) Pin
Dave Kreskowiak28-Dec-05 6:26
mveDave Kreskowiak28-Dec-05 6:26 
QuestionDeleting/Clearing programmically created controls Pin
Hmmkk28-Dec-05 3:46
Hmmkk28-Dec-05 3:46 
AnswerRe: Deleting/Clearing programmically created controls Pin
Dave Kreskowiak28-Dec-05 4:29
mveDave Kreskowiak28-Dec-05 4:29 
GeneralRe: Deleting/Clearing programmically created controls Pin
Hmmkk28-Dec-05 4:44
Hmmkk28-Dec-05 4:44 
GeneralRe: Deleting/Clearing programmically created controls Pin
Dave Kreskowiak28-Dec-05 5:01
mveDave Kreskowiak28-Dec-05 5:01 
GeneralRe: Deleting/Clearing programmically created controls Pin
Hmmkk28-Dec-05 5:15
Hmmkk28-Dec-05 5:15 
GeneralRe: Deleting/Clearing programmically created controls Pin
Dave Kreskowiak28-Dec-05 5:50
mveDave Kreskowiak28-Dec-05 5:50 
Hmmkk wrote:
But well I guess you have solved my current problem so Thanks alot but how exactly did you mean that the array you were talking about would look like?


I don't have a clue what your getting at here...

Controls() is an array, or Collection, of, well, Control objects. If you have 10 panel controls on your form, there will be 10 Panel controls in the Controls collection, at index positions 0 through 9. Controls.Count will return 10.

Now, you setup your loop to hit every index in the Controls collection, 0 through 9, using:
For j As Integer = 0 To Me.Controls.Count - 1

This will setup the loop to increment j from 0 to 9. Once it's setup, there's no changing the limits of the loop.

Next, you eventually find your first panel control and Dispose it. Now, without executing any other statements, what do you think Controls.Count is going to return? It's not 10 anymore, it's 9. The new VALID index values are now 0 through 8, not 9. But your loop is going to run until j reaches 9... See what the problem is?



Now, to your OTHER loop. The one that is putting together panel control names.
For i As Integer = 1 To 10
    a = "pnlThing" & i
.
.
.
Next

You're creating 10 names for panel controls, one at a time. When the first panel control name is built, you execute another loop to go through ALL the controls on the form, looking for the ONE control with this name. If there are 100 controls on the form, and your looking for 10 names, your actually looking at the names of 1,000 controls! Why??????

If you name your deletable panel controls with a unique name prefix, you can skip looking for 10 different control names that match each one of these names exactly and just search the Controls collection ONCE (100 controls in this example), and look for names that START WITH the name you're using to name DELETABLE controls. Like...
For i As Integer = Me.Controls.Count - 1 To 0 Step -1
    If Me.Controls(i).Name.StartsWith("DeletablePanel") Then
        Me.Controls(i).Dispose()
    End If
Next

Of course, your panel controls will have to be created with the names DeletablePanel1, DeletablePanel2, DeletablePanel3, DeletablePanel4, ...


RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

QuestionRe: Deleting/Clearing programmically created controls Pin
Hmmkk28-Dec-05 6:41
Hmmkk28-Dec-05 6:41 
AnswerRe: Deleting/Clearing programmically created controls Pin
Dave Kreskowiak28-Dec-05 13:14
mveDave Kreskowiak28-Dec-05 13:14 
GeneralRe: Deleting/Clearing programmically created controls Pin
Hmmkk28-Dec-05 14:58
Hmmkk28-Dec-05 14:58 
GeneralRe: Deleting/Clearing programmically created controls Pin
Dave Kreskowiak28-Dec-05 16:06
mveDave Kreskowiak28-Dec-05 16:06 
QuestionHowTo: HTML_2_Image Pin
Dredy28-Dec-05 0:58
Dredy28-Dec-05 0:58 
Questionstill excel remains in memory Pin
jith - iii27-Dec-05 22:54
jith - iii27-Dec-05 22:54 
QuestionHow to communicate with serial port in VB.NET Pin
kusikue27-Dec-05 22:46
kusikue27-Dec-05 22:46 
AnswerRe: How to communicate with serial port in VB.NET Pin
Dave Kreskowiak28-Dec-05 4:34
mveDave Kreskowiak28-Dec-05 4:34 
GeneralRe: How to communicate with serial port in VB.NET Pin
WillemM28-Dec-05 8:55
WillemM28-Dec-05 8:55 
QuestionGet previously active window?? Pin
matsnas27-Dec-05 22:29
matsnas27-Dec-05 22:29 
AnswerRe: Get previously active window?? Pin
Dave Kreskowiak28-Dec-05 4:46
mveDave Kreskowiak28-Dec-05 4:46 
QuestionWinForm LifeCycle.. Pin
HakunaMatada27-Dec-05 19:52
HakunaMatada27-Dec-05 19:52 
AnswerRe: WinForm LifeCycle.. Pin
Dave Kreskowiak28-Dec-05 4:37
mveDave Kreskowiak28-Dec-05 4:37 
GeneralRe: WinForm LifeCycle.. Pin
HakunaMatada28-Dec-05 17:24
HakunaMatada28-Dec-05 17:24 
GeneralRe: WinForm LifeCycle.. Pin
Dave Kreskowiak29-Dec-05 5:18
mveDave Kreskowiak29-Dec-05 5:18 
GeneralRe: WinForm LifeCycle.. Pin
HakunaMatada29-Dec-05 17:11
HakunaMatada29-Dec-05 17:11 
QuestionDataGridTextBoxColumn can hold the ComboBox ?? Pin
HemaRawat27-Dec-05 19:17
HemaRawat27-Dec-05 19:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.