472,352 Members | 1,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,352 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 2854
> 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...
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 ...
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...
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...
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...
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...
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...
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...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.