![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 3
Rep Power: 0
![]() |
Hello everyone,
I'm working on a program that involves adding alot of numbers that are in textbox arrays and popping the sum out into a list box. What I'd like to do is write a function that runs through any array that I give it, adds the numbers and sends back the sum, but I can't figure out how to make the function accept the array. Is it possible to send a control array to a function? If so, what's the proper syntax to do so? What I'm trying to do is something like this: Public Function addArray (arrayOfNumbers As ????) As Integer
Dim sum as Integer
For i = 0 to arrayOfNumbers.UBound
sum = sum + arrayOfNumbers(i)
Next
addArray = sum
End FunctionI can't think of a better way to do this, because I'd rather not have 8 or 9 separate pieces of code that do the same thing to different arrays. Peace.
__________________
Shameless Plug |
|
|
|
|
|
#2 |
|
Expert Programmer
|
Logically you should be able to do this:
Private Sub MyFunction(ByRef MyArray() as TextBox) however, VB in its strange way, actually doesn't hold control arrays on forms in the same way as arrays of variables. Similarly the ParamArray keyword won't work. Even if you did get it through, ubound() and lbound() don't work on control arrays, nor does the For Each syntax. The only way I can see of doing it is to pass the control array range to the routine (i.e. the upper and lower bounds). |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|