Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Does VB allow function pointers?

1 view
Skip to first unread message

Renny Bosch

unread,
Jan 3, 2010, 5:19:26 PM1/3/10
to
I have a table that lists a large number of math problems, it contains the
problem number, problem name, problem description, and name of the sub to be
executed to solve the problem. I also have a form with a combo box that
shows the descriptions of those problems. When I click on a particlular
entry, I would like to execute the sub whose name is listed in the table.

One way to do this is to have a long list of
If name = "xxxnn" then
xxxnn
ElseIf name = "xxxny" then xxxny
. . .
Endif
statements. Is it possible in VB to call a sub using a variable that
contains the sub's name? Something like:
name = "xxxnn"
IndirectCall name

Or some other technique?


Wolfgang Enzinger

unread,
Jan 3, 2010, 5:42:00 PM1/3/10
to
On Sun, 3 Jan 2010 14:19:26 -0800, Renny Bosch wrote:

>Is it possible in VB to call a sub using a variable that
>contains the sub's name? Something like:
>name = "xxxnn"
>IndirectCall name
>
>Or some other technique?

Lookup "CallByName" (VB6 only), that should do what you're looking for.
Not exactly a function pointer, but effectively the same thing.

Nobody

unread,
Jan 3, 2010, 7:19:44 PM1/3/10
to
What version of VB are you using?


Renny Bosch

unread,
Jan 3, 2010, 7:31:19 PM1/3/10
to
Thank you Wolfgang, that was exactly what I was looking for. The vb help
system is not as helpful as it used to be, but this newsgroup is terrific.

"Wolfgang Enzinger" <usenet...@temporaryforwarding.com> wrote in message
news:h272k5tdalnui5tkd...@4ax.com...

Renny Bosch

unread,
Jan 5, 2010, 7:37:46 PM1/5/10
to

It's version 6.5.

"Nobody" <nob...@nobody.com> wrote in message
news:OmvtxONj...@TK2MSFTNGP02.phx.gbl...

MikeD

unread,
Jan 5, 2010, 11:46:28 PM1/5/10
to
No such version of VB. Is this actually VBA?

--
Mike


"Renny Bosch" <non...@nospam.com> wrote in message
news:uMu84hmj...@TK2MSFTNGP04.phx.gbl...

Mike Williams

unread,
Jan 6, 2010, 3:48:02 AM1/6/10
to
"Renny Bosch" <non...@nospam.com> wrote in message
news:uMu84hmj...@TK2MSFTNGP04.phx.gbl...

> It's version 6.5.

That's VBA. This group deals with the full version of Visual Basic, which is
not the same thing. You should really post your VBA questions to a VBA
newsgroup, preferably one dedicated to the application you are using (Word,
Excel or whatever). However, for the record, the CallByName function, which
provides the answer to your question, does actually work okay in VBA.

Mike

Ralph

unread,
Jan 6, 2010, 8:27:42 AM1/6/10
to

Which is not surprising since the VB6 development platform uses the VBA 6.5
parser and libraries. <g>

-ralph


Renny Bosch

unread,
Jan 6, 2010, 9:40:24 PM1/6/10
to
Thanks Mike, I will ask in the Access group in the future. (I actually
didn't know the distinction between VB and VBA, so I learned something.)

Renny

"Mike Williams" <Mi...@WhiskyAndCoke.com> wrote in message
news:e5CN1zqj...@TK2MSFTNGP05.phx.gbl...

0 new messages