Calling a sub name held in a variable 
Author Message
 Calling a sub name held in a variable

My menu items are held in a database, along with the associated program to
run when that menu item is chosen. I load the menu at runtime, and when the
user clicks on the menu item in the treeview, I want to call the sub or
function held in the "tag" property of the selected item.

something like this:

Call tvwMenu.SelectedItem.Tag , where tvwMenu.SelectedItem.Tag =
"printbilling"

Any suggestions?

Thanks

Michael



Tue, 28 Jun 2005 11:53:50 GMT  
 Calling a sub name held in a variable
Try using the CallByName command



Quote:
> My menu items are held in a database, along with the associated program to
> run when that menu item is chosen. I load the menu at runtime, and when
the
> user clicks on the menu item in the treeview, I want to call the sub or
> function held in the "tag" property of the selected item.

> something like this:

> Call tvwMenu.SelectedItem.Tag , where tvwMenu.SelectedItem.Tag =
> "printbilling"

> Any suggestions?

> Thanks

> Michael



Tue, 28 Jun 2005 22:32:47 GMT  
 Calling a sub name held in a variable
I've tried this:
Call CallByName(me.lblMenuItem, "Caption, vbGet)
and
CallByName me.lblMenuItem, "Caption", vbGet
and
strCodeToRun = CallByName me.lblMenuItem, "Caption", vbGet
call strCodeToRun

This is all the same as:
Call Me.lblMenuItem.Caption
is it not?

None of the above work.

Can you help more?


Quote:
> Try using the CallByName command



> > My menu items are held in a database, along with the associated program
to
> > run when that menu item is chosen. I load the menu at runtime, and when
> the
> > user clicks on the menu item in the treeview, I want to call the sub or
> > function held in the "tag" property of the selected item.

> > something like this:

> > Call tvwMenu.SelectedItem.Tag , where tvwMenu.SelectedItem.Tag =
> > "printbilling"

> > Any suggestions?

> > Thanks

> > Michael



Wed, 29 Jun 2005 00:57:41 GMT  
 Calling a sub name held in a variable
Check out the CallByName function.


Quote:
> My menu items are held in a database, along with the associated program to
> run when that menu item is chosen. I load the menu at runtime, and when the
> user clicks on the menu item in the treeview, I want to call the sub or
> function held in the "tag" property of the selected item.

> something like this:

> Call tvwMenu.SelectedItem.Tag , where tvwMenu.SelectedItem.Tag =
> "printbilling"

> Any suggestions?

> Thanks

> Michael



Wed, 29 Jun 2005 01:43:00 GMT  
 Calling a sub name held in a variable
I don't think you can call a Sub or Func with a variable or const as the
name. Could be it's possible by some API call.
/Henning



Quote:
> My menu items are held in a database, along with the associated program to
> run when that menu item is chosen. I load the menu at runtime, and when
the
> user clicks on the menu item in the treeview, I want to call the sub or
> function held in the "tag" property of the selected item.

> something like this:

> Call tvwMenu.SelectedItem.Tag , where tvwMenu.SelectedItem.Tag =
> "printbilling"

> Any suggestions?

> Thanks

> Michael



Wed, 29 Jun 2005 04:51:00 GMT  
 Calling a sub name held in a variable
First, I suggest to read some help about the CallByName function,
Since it's more advanced than simple functions

Try using MSDN documention if you have it installed, or also at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr...
vafctcallbynamefunction.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn...
vbconCallingPropertyOrMethodUsingStringName.asp

Quote:
> This is all the same as:
> Call Me.lblMenuItem.Caption
> is it not?

In this case it's the same, although when using 'Call' the return value is
ignored.

I didn't quite understand, how the TreeView is related to the dynamic menus?

In anycase, you can't perform the executaion of 'Call
Me.lblMenuItem.Caption'
dynamically at run time, just because a .Tag property of some object,
specified it as a text.
This is where CallByName can help
(Unless, you perform Case  block for all possible choices, which is less
convenient)

You specified that this is what you need:

Quote:
> Call tvwMenu.SelectedItem.Tag , where tvwMenu.SelectedItem.Tag =

"printbilling"

In order to execute it using CallByName, then a procedure called
printbilling must exists!!!
Also in case you write the printbilling procedure, then it  need to be
Public.

One problem though, in case the printbilling procedure excepts argument,
and/or has a return value,
then you need to know it in advance, so you could pass those arguments.
In case the procedures you plan to execute according to the text in the .Tag
property,
Have different arguments list, then a general CallByName call is not good
enough.

If all of the procedure you plan to execute have the same arguments type,
and return value type.
Then you can use CallByName easily.

If the above explanation doesn't solve your problem,
Please send me your sources (ONLY IF IT'S NOT CLASSIFIED),
and detailed explanation of what you try to achieve,
since there might be other solutions to your problems, like using interfaces



Quote:
> I've tried this:
> Call CallByName(me.lblMenuItem, "Caption, vbGet)
> and
> CallByName me.lblMenuItem, "Caption", vbGet
> and
> strCodeToRun = CallByName me.lblMenuItem, "Caption", vbGet
> call strCodeToRun

> This is all the same as:
> Call Me.lblMenuItem.Caption
> is it not?

> None of the above work.

> Can you help more?



> > Try using the CallByName command



> > > My menu items are held in a database, along with the associated
program
> to
> > > run when that menu item is chosen. I load the menu at runtime, and
when
> > the
> > > user clicks on the menu item in the treeview, I want to call the sub
or
> > > function held in the "tag" property of the selected item.

> > > something like this:

> > > Call tvwMenu.SelectedItem.Tag , where tvwMenu.SelectedItem.Tag =
> > > "printbilling"

> > > Any suggestions?

> > > Thanks

> > > Michael



Wed, 29 Jun 2005 19:46:47 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Calling a function/sub when a variable holds the name

2. Calling a sub or function using a variable through another sub or function

3. Automatic capitalization of variable names, type names, subs and functions

4. Simple Question - Variable's as Sub names

5. Calling Sub/Function name?

6. How to share variables or call Subs between two projects

7. Multiple variables when calling a Sub

8. Calling Functions or Subs with a variable

9. Call Sub as Variable Value???

10. Using a String Variable to Call a Sub

11. Use a variable to call a sub procedure??

12. Sub-Procedure call using Variable

 

 
Powered by phpBB® Forum Software