471,356 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Array of Class

Hi,

I must design a method that receive a Control object and return a single
value if it is a TextBox object, another value if it is a ComboBox object
and so on.

If I try a "if-else-if" loop, this will be very unhappy! Can I use a foreach
to make that? How declare and create the array for use in the operator "is"
(for test a Control, like "cont is TextBox")?

Thanks,

Max
Jul 21 '05 #1
2 1072
If you want to enumerate the controls on a form, you can do this. I guess
this would be easy to change to accept a control as a parameter and evaluate
it.

Dim c As Control

For Each c In Me.Controls

If c.GetType.ToString = "System.Windows.Forms.TextBox" Then

Debug.Write("It's a button!!")

End If

Debug.Write(c.GetType.ToString)

Next

"Max André Bündchen" <.> wrote in message
news:ec**************@TK2MSFTNGP11.phx.gbl...
Hi,

I must design a method that receive a Control object and return a single
value if it is a TextBox object, another value if it is a ComboBox object
and so on.

If I try a "if-else-if" loop, this will be very unhappy! Can I use a
foreach
to make that? How declare and create the array for use in the operator
"is"
(for test a Control, like "cont is TextBox")?

Thanks,

Max

Jul 21 '05 #2
you could do this by overloading your method.

public string MyMethod(Button bc)
{
return "Button";
}
public string MyMethod(TextBox tb)
{
return "TextBox";
}

This is one of the easiest ways to do this.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Max André Bündchen" <.> wrote in message
news:ec**************@TK2MSFTNGP11.phx.gbl...
Hi,

I must design a method that receive a Control object and return a single
value if it is a TextBox object, another value if it is a ComboBox object
and so on.

If I try a "if-else-if" loop, this will be very unhappy! Can I use a foreach to make that? How declare and create the array for use in the operator "is" (for test a Control, like "cont is TextBox")?

Thanks,

Max

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by its me | last post: by
6 posts views Thread by Buddy Ackerman | last post: by
14 posts views Thread by Gianni Mariani | last post: by
3 posts views Thread by michi | last post: by
7 posts views Thread by Rade | last post: by
4 posts views Thread by Armand | last post: by
17 posts views Thread by =?Utf-8?B?U2hhcm9u?= | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.