Cancel
Showing results for 
Search instead for 
Did you mean: 

Optional arguments in methods

Legend
Legend

Hello,

 

I've tried to scour through the help files but can't seem to find anything about this.

 

Is there a way to create optional arguments in your own methods?

11 REPLIES 11

Re: Optional arguments in methods

Siemens Phenom Siemens Phenom
Siemens Phenom

Helllo,

 

no, this feature isn't available in SimTalk.

 

Regards,

Ralf

Regards,

Ralf
------------------------------------------------------------------------------------------------------
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.

Re: Optional arguments in methods

Legend
Legend

Any way that this could be implemented in the future?

Similarly as in C# where you set initial values to certain parameters and they will be regarded as optional since they have a default value.

 

Like this:

(firstArgument : string; optionalSecondArgument : string := "")
is
do
end;

 

 

Re: Optional arguments in methods

Siemens Phenom Siemens Phenom
Siemens Phenom

Currently it is not in our plans for one of the next versions.

 

We always have the tradeoff between simplicity and power of our programming language.

 

But we will give it another thought.

Regards,

Ralf
------------------------------------------------------------------------------------------------------
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.

Re: Optional arguments in methods

Siemens Legend Siemens Legend
Siemens Legend

Hello,

 

even without optional parameter there is some flexibility with the data type any as you can see below. Probably this can help?!

parameter_DT_any.png

 

Re: Optional arguments in methods

Legend
Legend

Yes, this is probably the best way to do it.

 

Especially coupled with makeArray to add as many or as few arguments as you wish and handle the rest in another method.

 

Thanks!

Re: Optional arguments in methods

Genius
Genius
I agree that it would be nice to have optional arguments.

C++ does this by allowing you to have multiple methods with the same name and it calls the method that matches the passed arguments.

Re: Optional arguments in methods

Siemens Phenom Siemens Phenom
Siemens Phenom
In version 13 we've added optional arguments with SimTalk 2.0.
Regards,

Ralf
------------------------------------------------------------------------------------------------------
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.

Re: Optional arguments in methods

Genius
Genius

Cool. How do you use them? I can't find any reference to that in the help. If I try it, I get the following error: "Wrong number of parameters in Method: x passed, x+1 expected."

 

Is there some way that you have to declare that this parameter is optional?

Re: Optional arguments in methods

Siemens Phenom Siemens Phenom
Siemens Phenom

Example:

param a: boolean, b,c: integer := 42, d: string := ""

 

In this case the Method can be called with 1 to 4 arguments (because b, c and d are optional).

_________________________________________________________________
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.