473,397 Members | 2,028 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,397 software developers and data experts.

How to pass a Control Array - VB5

I would like to pass a Control array of OptionButtons that I created at run
time to a Sub.

Say I have Opt(0), Opt(1)......Opt(5) as OptionButtons, is there a way to
pass Opt to a function and have the function see it as an Array of
Optionbuttons?

private sub Test(a as Object) is the best I can come up with so far. I
would like to test it to verify that it is both an array and an
OptionButton. Although I can check it with typename(Opt(opt.lbound)) for the
OptionButton part I am relying on Error checking to check to see if it is an
array. Is there a better way?

Thanks.
Jul 17 '05 #1
4 5901
http://vbnet.mvps.org/code/helpers/iscontrolinarray.htm - a one-line
function that returns True if the passed control is a member of a control
array, or False if it is not, and without requiring error trapping.

--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
"The Mess" <em***@none.com> wrote in message
news:_t********************@news20.bellglobal.com. ..
:I would like to pass a Control array of OptionButtons that I created at run
: time to a Sub.
:
: Say I have Opt(0), Opt(1)......Opt(5) as OptionButtons, is there a way to
: pass Opt to a function and have the function see it as an Array of
: Optionbuttons?
:
: private sub Test(a as Object) is the best I can come up with so far. I
: would like to test it to verify that it is both an array and an
: OptionButton. Although I can check it with typename(Opt(opt.lbound)) for
the
: OptionButton part I am relying on Error checking to check to see if it is
an
: array. Is there a better way?
:
: Thanks.
:
:

Jul 17 '05 #2
So that's how its done!
Thanks for the quick reply!

"Randy Birch" <rg************@mvps.org> wrote in message
news:1K********************@rogers.com...
http://vbnet.mvps.org/code/helpers/iscontrolinarray.htm - a one-line
function that returns True if the passed control is a member of a control
array, or False if it is not, and without requiring error trapping.

--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
"The Mess" <em***@none.com> wrote in message
news:_t********************@news20.bellglobal.com. ..
:I would like to pass a Control array of OptionButtons that I created at run : time to a Sub.
:
: Say I have Opt(0), Opt(1)......Opt(5) as OptionButtons, is there a way to : pass Opt to a function and have the function see it as an Array of
: Optionbuttons?
:
: private sub Test(a as Object) is the best I can come up with so far. I
: would like to test it to verify that it is both an array and an
: OptionButton. Although I can check it with typename(Opt(opt.lbound)) for
the
: OptionButton part I am relying on Error checking to check to see if it is an
: array. Is there a better way?
:
: Thanks.
:
:

Jul 17 '05 #3
> http://vbnet.mvps.org/code/helpers/iscontrolinarray.htm - a one-line
function that returns True if the passed control is a member of a control array, or False if it is not, and without requiring error trapping.


The following is from an email I sent you about 3 years ago. I'm
guessing we both lost track of it because it was never included in the
web page's text. (Either that, or you just don't like what I wrote.<g>)
Anyway, I'm posting it here because I think it adds something useful to
the discussion.

In the routine you cited in the above link, you offer four examples of
calling the IsControlInArray function listed in the routine. I think
they all miss the true usefulness of the code since you are calling the
IsControlInArray function using "hard coded" control objects. If you
know enough to pass Option2 instead of Option2(0) into the function, you
probably already know whether you have a control array or not (so you
don't need the function to tell you). I envisioned this codes usefulness
to be when used either with the ActiveControl property of a Form
(whether the ActiveForm or not) or when used in a Function/Sub where it
would use the control passed into the Function/Sub as its direct
argument. It is in these types of situations where the nature of the
control would not be known beforehand and asking IsControlInArray would
truly be useful.

Rick - MVP

Jul 17 '05 #4
Hi Rick ...

I thought I responded to that email. I agree, but also find the function
handy as it reliably determines the control type when a control of unknown
type passed to a method as object. As I could foresee use for this I
maintained the page ...

Private Sub Command1_Click()

Call something(Command1)
Call something(Command2)

End Sub

Private Sub something(obj As Object)

If IsControlInArray(obj) Then
obj(0).Caption = "an array control"
Else
obj.Caption = "non-array control"
End If

End Sub

Private Function IsControlInArray(ctl As Object) As Boolean

IsControlInArray = TypeName(ctl) = "Object"

End Function
Were you to use the same test with:

Private Sub Command2_Click(Index As Integer)

Call something(Me.ActiveControl)

End Sub

.... the result is "non-array control", as the control resolves to
CommandButton since effectively "Command(0)' or "Command2(1)" was passed.
--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:ro********************@comcast.com...
:> http://vbnet.mvps.org/code/helpers/iscontrolinarray.htm - a one-line
: > function that returns True if the passed control is a member of a
: control
: > array, or False if it is not, and without requiring error trapping.
:
: The following is from an email I sent you about 3 years ago. I'm
: guessing we both lost track of it because it was never included in the
: web page's text. (Either that, or you just don't like what I wrote.<g>)
: Anyway, I'm posting it here because I think it adds something useful to
: the discussion.
:
: In the routine you cited in the above link, you offer four examples of
: calling the IsControlInArray function listed in the routine. I think
: they all miss the true usefulness of the code since you are calling the
: IsControlInArray function using "hard coded" control objects. If you
: know enough to pass Option2 instead of Option2(0) into the function, you
: probably already know whether you have a control array or not (so you
: don't need the function to tell you). I envisioned this codes usefulness
: to be when used either with the ActiveControl property of a Form
: (whether the ActiveForm or not) or when used in a Function/Sub where it
: would use the control passed into the Function/Sub as its direct
: argument. It is in these types of situations where the nature of the
: control would not be known beforehand and asking IsControlInArray would
: truly be useful.
:
: Rick - MVP
:

Jul 17 '05 #5

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

Similar topics

4
by: Stephen Williams | last post by:
Hey i've got bunch of arrays of tick boxes, each array contains somewhere between 5 and 20. What I want to do is write a function that returns the captions of every ticked tick box in an array...
5
by: Seeker | last post by:
Newbie question here... I have a form with some radio buttons. To verify that at least one of the buttons was chosen I use the following code ("f" is my form object) : var btnChosen; for...
5
by: wilson | last post by:
Dear all, In this time, I want to pass array to function. What should I declare the parameter in the function?i int array or int array? Which one is correct? ...
7
by: liyang3 | last post by:
Hi, I have Class A, B and C. Class A has an instance of B. Class B has an instance of C. In the instance of C, it generates some data that need to be passed back to Class A. But Class C...
1
by: CraigLearningCSharp | last post by:
Hello, What is the best way to pass a 1D array of numbers in (and out) of a control? I've been looking at the property wizard and don't see an option for arrays? The idea is to make something...
2
by: Augusto Cesar | last post by:
Hello people. How can I Pass ASP Array variable to Javascript; I´m to trying this: <script language="JavaScript"> var x = new Array(10);
5
by: slowmotiongenius | last post by:
All- I have established an adodb recordset in my code-behind, and I need to pass it to the aspx file. I can't seem to figure out if there is a way to do this. I see you can pass a string over...
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.