473,811 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(op t.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 5927
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******** ************@ne ws20.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(op t.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******** ************@ro gers.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******** ************@ne ws20.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(op t.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 IsControlInArra y function listed in the routine. I think
they all miss the true usefulness of the code since you are calling the
IsControlInArra y 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 IsControlInArra y 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(Comma nd1)
Call something(Comma nd2)

End Sub

Private Sub something(obj As Object)

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

End Sub

Private Function IsControlInArra y(ctl As Object) As Boolean

IsControlInArra y = TypeName(ctl) = "Object"

End Function
Were you to use the same test with:

Private Sub Command2_Click( Index As Integer)

Call something(Me.Ac tiveControl)

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******** ************@co mcast.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 IsControlInArra y function listed in the routine. I think
: they all miss the true usefulness of the code since you are calling the
: IsControlInArra y 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 IsControlInArra y 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
2965
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 as a string. I want to be able to pass to the function the array name, and the lower and upper limits of the array. But I have no idea how to pass the control name (array name).
5
3152
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 (count = 0; count <= 1; count++) { if (eval(f.RadioButtons.checked)) { btnChosen = true; }
5
3428
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? /******************************************************** Below is my code: ********************************************************/
7
2075
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 doesnot know anything about Class A. I'm dealing with legacy code. What is the best way to implement it and have the code change to existing classes such as A and B small? Any
1
1365
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 like a graph control which graphs an array of 1D numbers. When I pass the numbers into the control, I want the control to update the graph. Or, another example is a simple control which displays the Mean, Min, and Max of a 1D array. I want to...
2
6451
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
3050
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 using the GetCallbackResult, but a recordset won't pass this way. Any ideas??? Thanks
24
55250
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 EventHandler(Onbutton_click); I want to pass more information related that event. & want to use that
12
11119
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. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed! (He knows this I'm sure, but just didn't think this was my problem; LOL, I am needling him) If...
0
9734
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10652
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10408
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10137
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9211
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6895
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4346
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3874
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3026
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.