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

loop thru list of functions?

Hi all,

I need to store a list of modules.functions() in an array
and then loop thru the array and call the functions. I
have not been able to get any code to work.

Here's what I need to do:

dim myArr(3) as string
myArr(0) = "MyModA.Func1()"
myArr(2) = "MyModA.Func2()"
myArr(3) = "MyModB.Func1()"
myArr(4) = "MyModB.Func2()"

dim iCnt, iRet as integer

FOR iCnt = 0 TO myArr.Length -1
iRet = myArr(0)
NEXT iCnt

I know why this doesn't work, but I
don't know how to figure out how to approach it.

Any help will be much appreciated.

Thanks,
Marc Miller
Jul 27 '06 #1
3 1015

Marc Miller wrote:
Hi all,

I need to store a list of modules.functions() in an array
and then loop thru the array and call the functions. I
have not been able to get any code to work.

Here's what I need to do:

dim myArr(3) as string
myArr(0) = "MyModA.Func1()"
myArr(2) = "MyModA.Func2()"
myArr(3) = "MyModB.Func1()"
myArr(4) = "MyModB.Func2()"

dim iCnt, iRet as integer

FOR iCnt = 0 TO myArr.Length -1
iRet = myArr(0)
NEXT iCnt

I know why this doesn't work, but I
don't know how to figure out how to approach it.

Any help will be much appreciated.

Thanks,
Marc Miller
System.Reflection should be able to list all the functions in a module.

As for calling them, i have no idea. Can Delegates be used somehow?

B.

Jul 27 '06 #2
I need to store a list of modules.functions() in an array and then
loop thru the array and call the functions. I have not been able to
get any code to work.

Here's what I need to do:

dim myArr(3) as string
myArr(0) = "MyModA.Func1()"
myArr(2) = "MyModA.Func2()"
myArr(3) = "MyModB.Func1()"
myArr(4) = "MyModB.Func2()"
dim iCnt, iRet as integer

FOR iCnt = 0 TO myArr.Length -1
iRet = myArr(0)
NEXT iCnt
I know why this doesn't work, but I
don't know how to figure out how to approach it.
Any help will be much appreciated.

Thanks,
Marc Miller
Below is a sample implementation using delegates. You will need to translate
it to use your objects and methods. The delegate scheme should be more performant
as it does not need to use reflection, but rather has direct pointers to
the method calls. Also, notice that the methods added to the list are strongly
typed rather than being latebound as strings in your example. Note that if
you need to pass parameters to the methods, things start to get a bit more
tricky. This should give you enough to get started though.

Public Class MyApplication
<STAThread()_
Public Shared Sub Main()
Dim tester As New MyDelegates
Dim methodList As New List(Of SampleDelegate)
methodList.Add(AddressOf tester.Test1)
methodList.Add(AddressOf tester.Test2)

For Each method As [Delegate] In methodList
method.Method.Invoke(tester, Nothing)
Next

Console.ReadLine()
End Sub
End Class

Public Class MyDelegates
Public Sub Test1()
Console.WriteLine("Testing 1")
End Sub
Public Sub Test2()
Console.WriteLine("Testing 2")
End Sub
End Class

Public Delegate Sub SampleDelegate()
Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
Jul 27 '06 #3
Calling a method by its name
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=callbyname&lang=en>
--
Terry
"Marc Miller" wrote:
Hi all,

I need to store a list of modules.functions() in an array
and then loop thru the array and call the functions. I
have not been able to get any code to work.

Here's what I need to do:

dim myArr(3) as string
myArr(0) = "MyModA.Func1()"
myArr(2) = "MyModA.Func2()"
myArr(3) = "MyModB.Func1()"
myArr(4) = "MyModB.Func2()"

dim iCnt, iRet as integer

FOR iCnt = 0 TO myArr.Length -1
iRet = myArr(0)
NEXT iCnt

I know why this doesn't work, but I
don't know how to figure out how to approach it.

Any help will be much appreciated.

Thanks,
Marc Miller
Jul 27 '06 #4

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

Similar topics

0
by: Charles Alexander | last post by:
Hello I am new to php & MySQL - I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Sample_ID Marker_ID Variation ...
5
by: Andrew Young | last post by:
How do I loop thru a result set Without using a curosr?
2
by: sparks | last post by:
I was going to loop thru the tables and change some properties. 10 <<<<<< prp.value --prp.name = Type False <<<<prp.value --prp.name = allow zero length 10 <<<<<< prp.value --prp.name = Type...
7
by: Alvin Bruney | last post by:
Error: Collection was modified; enumeration operation may not execute. I've dodged this issue for a while now with workarounds but now i want to stand up and fight. I don't want to run away...
9
by: Bill Nguyen | last post by:
I need a VB routine to loop thru a select top folder to find all subfolders and list all subfolders/files under each of these subfolders. Any help is greatly appreciated. Bill
5
by: Allerdyce.John | last post by:
Hi, I have this piece of code which loops thru a STL list, but that causs an infinite loop. bool Executer::group(MyList& bl, ResultList & grl) { for (ExecuterList::iterator i =...
6
by: doncee | last post by:
Using a multi select list box to open several records in a pre - defined form. Most of the code that follows is taken from a posting by Alan Browne on his web site. The click routine is supposed...
3
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Here is my loop and it runs fine: ---------------------------------------------------- sSQL = "SELECT * FROM STORE_ITEMS" Set DataRec = DB.execute(sSQL) if not DataRec.EOF then do while not...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
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...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.