Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 10th, 2005, 5:43 PM   #1
Aenimalius
Newbie
 
Aenimalius's Avatar
 
Join Date: Feb 2005
Posts: 3
Rep Power: 0 Aenimalius is on a distinguished road
Question Passing a control array to a function: Is it possible?

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 Function

I 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
Aenimalius is offline   Reply With Quote
Old Feb 13th, 2005, 5:55 PM   #2
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
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).
Rory is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:13 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC