473,394 Members | 1,693 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,394 software developers and data experts.

How do I pass the name of an array to a function or procedure?

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).

I can do it by writing a prodecure for every single array, but there are
hundreds of them! It must be possible using a single function or procedure.
I came up with this, it needs finishing.

Private Function ReturnString(ctrlName As ***WHAT?????**** , intLow As
Integer, intHigh As Integer) As String
intFlag = 0
strField = ""
For intCount = intLow To intHigh
If ctrlName(intCount).Value = 1 Then
If intFlag = 0 Then
strField = ctrlName(intCount).Caption
intFlag = 1
Else
strField = strField & ", " & ctrlName(intCount).Caption
End If
End If
Next intCount
ReturnString = strField
End Function
Thanks for any help

Steve
Jul 17 '05 #1
4 2945
> 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).

I can do it by writing a prodecure for every single array, but there are hundreds of them! It must be possible using a single function or procedure. I came up with this, it needs finishing.

Private Function ReturnString(ctrlName As ***WHAT?????**** , intLow As
Integer, intHigh As Integer) As String
intFlag = 0
strField = ""
For intCount = intLow To intHigh
If ctrlName(intCount).Value = 1 Then
If intFlag = 0 Then
strField = ctrlName(intCount).Caption
intFlag = 1
Else
strField = strField & ", " & ctrlName(intCount).Caption
End If
End If
Next intCount
ReturnString = strField
End Function


Three points. First, declare the ctrName argument as Object. Second, Dim
all of your variables. Right now, every variable in your Function is a
Variant. Variants execute slower than declared variables and they take
up more memory. Third, you don't need to pass the lower and higher
indexes of the control array because VB will already knows them. Inside
of the Function, you could set your For-Next loop like this (and
eliminate intLow and intHigh altogether).

For intCount = ctrlName.LBound to ctrlName.UBound

HOWEVER, there is an even better way to handle this... use a For Each
loop. You will need to

Dim ctrl As Control

and then change your loop to this...

For Each ctrl In ctrlName
If ctrl.Value = 1 Then
If intFlag = 0 Then
strField = ctrl.Caption
intFlag = 1
Else
strField = strField & ", " & ctrl.Caption
End If
End If
Next

Rick - MVP

Jul 17 '05 #2
On Mon, 26 Jul 2004 18:34:35 +1200, "Stephen Williams"
<st*****@hotmail.com> wrote:
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).

I can do it by writing a prodecure for every single array, but there are
hundreds of them! It must be possible using a single function or procedure.
I came up with this, it needs finishing.


Option Explicit

Private Sub Command1_Click()
Call LS_SetCheckBoxes(Check1)
End Sub

Sub LS_SetCheckBoxes(Check1 As Object)
Dim C As CheckBox

For Each C In Check1
Select Case C.Value
Case vbChecked: C.Value = vbUnchecked
Case vbUnchecked: C.Value = vbChecked
End Select
Next
' --- Also
Me.Print Check1.LBound
Me.Print Check1.UBound
End Sub

Jul 17 '05 #3
>
Three points. First, declare the ctrName argument as Object. Second, Dim
all of your variables. Right now, every variable in your Function is a
Variant. Variants execute slower than declared variables and they take
up more memory. Third, you don't need to pass the lower and higher
indexes of the control array because VB will already knows them. Inside
of the Function, you could set your For-Next loop like this (and
eliminate intLow and intHigh altogether).


Bingo! Thank you very much.

My variables were already declared, I was using them elsewhere in and was
only writing that function after writing 10 nearly identical prodedures.

I do need to pass the lower and higher indexes, unfortunatly I was running
out of room on the form thanks to having so many check boxes. Many arrays
for example have elements 0 to 13 as checkboxes, then another one at 99.

Very bad code I know, but I'll be able to clean it up after the deadline by
replacing the arrays with a user control.

Steve
Jul 17 '05 #4
> Option Explicit

Private Sub Command1_Click()
Call LS_SetCheckBoxes(Check1)
End Sub

Sub LS_SetCheckBoxes(Check1 As Object)
Dim C As CheckBox

For Each C In Check1
Select Case C.Value
Case vbChecked: C.Value = vbUnchecked
Case vbUnchecked: C.Value = vbChecked
End Select
Next
' --- Also
Me.Print Check1.LBound
Me.Print Check1.UBound
End Sub


Thank you very much.

I can't belive I had no idea about the Object variable.

Steve
Jul 17 '05 #5

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

Similar topics

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...
2
by: Nelson Xu | last post by:
Hi All Does anyone knows how to pass an array from .net application to oracle stored procedure Thank you in advance Nelson
1
by: Mark Dicken | last post by:
Hi All I have found the following Microsoft Technet 'Q' Article :- Q210368 -ACC2000: How to Pass an Array as an Argument to a Procedure (I've also copied and pasted the whole contents into...
0
by: Zlatko Matić | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems...
7
by: ritchie | last post by:
Hi all, I am new to this group and I have question that you may be able to help me with. I am trying to learn C but am currently stuck on this. First of all, I have a function for each sort...
9
by: Alan Silver | last post by:
Hello, I'm a bit surprised at the amount of boilerplate code required to do standard data access in .NET and was looking for a way to improve matters. In Classic ASP, I used to have a common...
4
by: _Mario.lat | last post by:
Hallo, I have a little question: In the function session_set_save_handler I can pass the name of function which deal with session. In Xoops code I see the use of this function like that: ...
14
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
10
by: Robert Dailey | last post by:
Hi, I noticed in Python all function parameters seem to be passed by reference. This means that when I modify the value of a variable of a function, the value of the variable externally from the...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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...

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.