Calling a function from a string

  • Thread starter Thread starter GB
  • Start date Start date
G

GB

Is there a way to call a function from a string instead of calling the
function explictly?

For example:

dim fooStr as string

fooStr = "foo1"

' The question:
' Can I call foo1 by passing the string value contained in fooStr?

function foo1() as string
return "foo1's value"
end function

function foo2() as string
return "foo2's value"
end function
 
GB said:
Is there a way to call a function from a string instead of calling
the function explictly?

For example:

dim fooStr as string

fooStr = "foo1"

' The question:
' Can I call foo1 by passing the string value contained in fooStr?

function foo1() as string
return "foo1's value"
end function

function foo2() as string
return "foo2's value"
end function


You can use CallByName (member of Microsoft.VisualBasic.Interaction), but it
is as slow as unsafe because the compiler can't resolve the names.
 
* "GB said:
Is there a way to call a function from a string instead of calling the
function explictly?

For example:

dim fooStr as string

fooStr = "foo1"

' The question:
' Can I call foo1 by passing the string value contained in fooStr?

function foo1() as string
return "foo1's value"
end function

function foo2() as string
return "foo2's value"
end function

You will find a nice explanation here:

<http://www.google.com/[email protected]>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
 
Back
Top