calling variable sub methods

Hello,

Is it possible that when I want to run a sub method. I can use a variable as method name?

Example:
var V_SubMethod = ‘method3’
var Run = ‘forms.form1.’ + V_SubMethod + ‘()’
Run

The variable Run contains the right syntax however it is just plain text and not a command.

Is there another way to do so.

Perhaps a “text to command” conversion is a simple feature to tackle a great range of “customized commands”.
EG.
Run.TextToCommand

With kind regards Rene

Rene,
try this

var V_SubMethod = ‘method3’;
eval(V_SubMethod + “()”);

Thanks r.rios

It did the job perfectly.

Let`s see if I understand this function correct

eval(objectstring)

Returns an object string wich can trigger a command representing that object string. This object string can be generated through a calculation.

If this is correct it`s an awesome function wich makes it possible to calculate actions rather than use a complex if {} else {} etc. statement

Thanks very much again :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol:

Rene

Rene:
If this is correct it`s an awesome function wich makes it possible to calculate actions rather than use a complex if {} else {} etc. statement

Keep in mind that using eval is much slower as the code will have to be interpreted at runtime and also that it can cause security issues (if you for example evaluate code in a field then a user can potentially put any type of javascript in that field)

Rene:
Hello,

Is it possible that when I want to run a sub method. I can use a variable as method name?

Example:
var V_SubMethod = ‘method3’
var Run = ‘forms.form1.’ + V_SubMethod + ‘()’
Run

This should work as well:

forms.form1V_SubMethod;

Object references can be replaced with a variable using square brackets.

  • david