473,387 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,387 software developers and data experts.

VBA array of functions

Roy
Is there a way of declaring an array of functions (or subs) in VBA?

Sep 21 '06 #1
3 7200
Like in Javascript? I'm inclined to say No.

What do you want? Eval() can call a function of which you know the name
(in a string variable)

Roy schreef:
Is there a way of declaring an array of functions (or subs) in VBA?
--
Bas Cost Budde
Holland
Sep 21 '06 #2
Hi Roy,

You can use a collection object to store the names of
functions/procedures that you can call in a loop. Another option is to
use a Class module and have a collection object inside the class module.
YOu can reference the class object (your class module at runtime) and
loop through the collection object of the class object and also
reference its properties and methods.

Save a class module as clsABC, for example. Two things that sets the
Class module apart from a standard module is that

1) you can instantiate a class module as an object

Dim ABC As New clsABC

2) you can initialize a class module using the class module Initialize
event (in the right dropdown box at the top of the module). This is
similar to a contructor in an OOP class like in VB.Net (except you don't
get inheritance since VBA is not OOP)

Of course, you can also call/reference the public members of the class
module which will show up in a dropdown list of any variable you
instantiate as that class.

Dim ABC As New clsABC

now ABC will have intellisense - if you add a period . to the end of
ABC. you will get a dropdown list of anything you declared as public in
clsABC. Class modules are a good place to store collection object.

Rich
*** Sent via Developersdex http://www.developersdex.com ***
Sep 21 '06 #3
Roy
This looks promising. Thanks ... and thanks to the other respondent.
Rich P wrote:
Hi Roy,

You can use a collection object to store the names of
functions/procedures that you can call in a loop. Another option is to
use a Class module and have a collection object inside the class module.
YOu can reference the class object (your class module at runtime) and
loop through the collection object of the class object and also
reference its properties and methods.

Save a class module as clsABC, for example. Two things that sets the
Class module apart from a standard module is that

1) you can instantiate a class module as an object

Dim ABC As New clsABC

2) you can initialize a class module using the class module Initialize
event (in the right dropdown box at the top of the module). This is
similar to a contructor in an OOP class like in VB.Net (except you don't
get inheritance since VBA is not OOP)

Of course, you can also call/reference the public members of the class
module which will show up in a dropdown list of any variable you
instantiate as that class.

Dim ABC As New clsABC

now ABC will have intellisense - if you add a period . to the end of
ABC. you will get a dropdown list of anything you declared as public in
clsABC. Class modules are a good place to store collection object.

Rich
*** Sent via Developersdex http://www.developersdex.com ***
Sep 21 '06 #4

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

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
4
by: Mark Hannon | last post by:
I am trying to initialize an array only once so it can be seen & used by any functions that need it. As I understand it, if a variable is declared by itself outside of any functions, its scope is...
32
by: Carson | last post by:
Hi , Is there a very efficient way to set a double array to 0 ? (I have tried memset, but the result doesn't look correct.) Carson
5
by: Steve | last post by:
Can anyone tell me if I can have an array of functions that take a variable number of parameters? If it is possible I'd like to know how to declare the array and the functions as its elements. I am...
7
by: arkobose | last post by:
hey everyone! i have this little problem. consider the following declaration: char *array = {"wilson", "string of any size", "etc", "input"}; this is a common data structure used to store...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
9
by: JoeC | last post by:
I am crating a new version of my map game and my map will be a 2d array. I had problems trying to create a 2d array dynamically, in fact C++ won't let me do it. My question is how to create the...
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...
5
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
3
by: David K in San Jose | last post by:
I'm using managed (CLR) C++ in VS2005 to create a Windows app that contains a form named "MyForm". In the code for that form I'm trying to invoke some static functions by using an array of function...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
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...

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.