A Way to work around no object indexes?
A Way to work around no object indexes?
A Way to work around no object indexes?
A Way to work around no object indexes?
A Way to work around no object indexes?
A Way to work around no object indexes? A Way to work around no object indexes? A Way to work around no object indexes? A Way to work around no object indexes? A Way to work around no object indexes? A Way to work around no object indexes? A Way to work around no object indexes? A Way to work around no object indexes?
A Way to work around no object indexes? A Way to work around no object indexes?
A Way to work around no object indexes?
Go Back  Xtreme Visual Basic Talk > > > A Way to work around no object indexes?


Reply
 
Thread Tools Display Modes
  #1  
Old 01-22-2011, 11:46 AM
HellfireXP's Avatar
HellfireXP HellfireXP is offline
Freshman
 
Join Date: May 2010
Location: South Carolina
Posts: 41
Default A Way to work around no object indexes?


I am working with VB 2010, and am trying to figure out a way to condense the amount of code I am going to have to write for a project I am working on. My problem comes from the lack of ability to index objects, such as Buttons.

In VB6, I could create 5 buttons (for example) indexed 0 to 4, then using a simple for...next loop, do something specific with each button.

OLD WAY (VB6):
Code:
For i as integer = 0 to 4
  Abutton(i).Caption = "Click Button " & i
Next i
However, for the life of me, I can't find an easy way to accomplish a similar task in VB 2010. I understand using the "Handle ButtonX" concept, but this seems to only be useful if I want to do the same thing with each button, and even then I'm still plugging in code for every single button (example below):

VB 2010:
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click
        Button1.BackColor = Color.Red
        Button2.BackColor = Color.Red
    End Sub
Is there a way in VB 2010 to do something similar to the first example from VB6? For the sake of simplicity, what's the simplest way to go through a set of 10 buttons and rename each of them "Click Button [Index]".

Thanks.
Reply With Quote
  #2  
Old 01-22-2011, 12:29 PM
passel's Avatar
passelA Way to work around no object indexes? passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Have you read the tutorial on control arrays. With a bit of work, you can emulate the logic as you would would vb6 control arrays.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
A Way to work around no object indexes?
A Way to work around no object indexes?
A Way to work around no object indexes? A Way to work around no object indexes?
A Way to work around no object indexes?
A Way to work around no object indexes?
A Way to work around no object indexes? A Way to work around no object indexes? A Way to work around no object indexes? A Way to work around no object indexes? A Way to work around no object indexes? A Way to work around no object indexes? A Way to work around no object indexes?
A Way to work around no object indexes?
A Way to work around no object indexes?
 
A Way to work around no object indexes?
A Way to work around no object indexes?
 
-->