Can I call a VB function by address?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to call a function in VB by knowing the adress of the
function? I know this can be done in C. Here is a simplified description of
what I want to do.

Through a Comm port or TCP input, I get a command word. Based on the
command, I want to execute a function. Since I expect to have a large number
of command words, I plan on using a hash table to convert the command word to
an index. Now, with the index I can execute a function. I can use a select
case block but I wonder if that is efficient. I was thinking about having an
array of function addresses and then using the index from the hash table as
an array index to point to the address of the function.

Any suggestions here?

Hamil.
 
Hi,

Take a look at delegates.
http://msdn.microsoft.com/library/d.../cpref/html/frlrfsystemdelegateclasstopic.asp

Ken
-------------------
Is there a way to call a function in VB by knowing the adress of the
function? I know this can be done in C. Here is a simplified description of
what I want to do.

Through a Comm port or TCP input, I get a command word. Based on the
command, I want to execute a function. Since I expect to have a large number
of command words, I plan on using a hash table to convert the command word
to
an index. Now, with the index I can execute a function. I can use a select
case block but I wonder if that is efficient. I was thinking about having an
array of function addresses and then using the index from the hash table as
an array index to point to the address of the function.

Any suggestions here?

Hamil.
 
One possibility is to use Reflection to call functions by name, but it will
be slow. Another one is to use delegates (kind of pointers to functions),
which seems better. But try to measure the performance of the select case
block before using those alternatives.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top