Sept. 9, 2006
Hey Darrell... so what you want to do is just use a method to look up your
control name in the Me container basically.....
Common to other "container" objects (including big ones like Groupboxes,
panels, etc, and small ones like user controls), there is a "Controls"
property of Me to find a control. . . use the Find method (pass the ID of
the control - like Button1, and then pass True to search all child controls
as the second parameter).
This Me.Controls.Find method returns an array of Object types. . . . with
each member of the array being a match to your control ID paramter -
however, I absolutely have no idea how you could have more than one control
returned because .Net doesn't allow two controls to have the same name.
So since we know at design time that it will only return one object in that
array, we just use the first member - ie, Object(0) member.
So we've got our control by specifying the 0 index of the object array, but
since it is still of an Object type, we need to cast it to a Button type so
we can change its properties. . . which is done with the
Ctype(OriginalObject, newtypename) operation...
'loop with I as integer being your button1 , 2, 3, 4 etc
dim O() as object = Me.Controls.Find("Button" & I, True)
dim OurButton as Button = O(0)
*OurButton.Property = New Value
or in a very condensed form if you were only going to change 1 property:
Ctype(Me.Controls.Find("Button" & I, True)(0), Button).Property = Value
Hopefully this works for you!
--
Joseph Bittman
Microsoft Certified Solution Developer
Microsoft Most Valuable Professional -- DPM
Blog/Web Site:
http://CactiDevelopers.ResDev.Net/
darrell said:
Thanks for responding, Joseph.
example 1:
For rowCtr = 2 To 5
With Me("TextBox" & rowCtr)
.borderstyle = Fixed3D
.BackColor = BlanchedAlmond
End With
Next rowCtr
example 2:
With Me.TextBox2
.BorderStyle = BorderStyle.Fixed3D
.BackColor = Color.BlanchedAlmond
End With
repeat for TextBox3 through <whatever>
or
Me.TextBox2.BorderStyle = BorderStyle.Fixed3D
Me.TextBox2.BackColor = Color.BlanchedAlmond
repeat for TextBox3 through <whatever>
I have four textboxes on my form (in this example), named TextBox2 through
TextBox5. In VBA for Access, example 1 works - no squawks. In dotnet
VB, example 1 bombs, example 2 though works fine. That's fine for three
or four boxes...for ten or twelve, it's a pain. I'm constantly changing
background colors, and am developing with the border style set to
FixedSingle. It seems to me that VB dotnet should be able to something
like example 1.
Darrell
Sept. 9, 2006
Hey Darrell... the "With" statement is to help cut down on the code you
have to write if you are going to be repeatingly changing settings on a
control. . . and therefore the syntax is "With [objectname]". The problem
you are running into is there is no "object' repesented by "Me("r" &
rowCtr & "w" & whlCtr)".
Me is the current component the code is running under, and passing
something between ()s doesn't give anything back. You can do what you are
wanting with *other* components such as collections...
dim A() as string
With A(3) ' Represents the 4th string object in this 0-based string array
end with
A.GetValue(int) is the set default property for people who want to use
the short-hand version A(int)... it is just a shortcut. So while each
class can have a different type of default property & parameters, the
"Me" class doesn't have one.
So if there is an object in Me which you need... you'll need to dig
through Intellisense for Me to find the property/function you need to
call to get the contained object.
If you let us know what the object is and what it is doing in Me, then we
could probably help you in finding the property/function you need.
Hope this helps!