Optional parameters in functions

Tbi
Member Posts: 33
Hi
I'm writing some codeunits, and tries to find out how to make a function with optional parameter(s).
Is this possible, and if, how?
I'm writing some codeunits, and tries to find out how to make a function with optional parameter(s).
Is this possible, and if, how?
0
Comments
-
I think, that it is no possible to have function with variable count of parameters. No way how to do that. No way to set default value for some parameter, no way how to define more functions with same name but another parameter count.
But> one place where are functions with variable count of parameters exist> automations.... if you look to some code with automations, there are used many functions with default parameters...0 -
example:
define the following variables:
Name Type
ParameterInput Dialog
Parameter1 Integer
Parameter2 Integer
Parameter3 Integer
Text Constant:
Name ConstValue
Text1000000003 Please Specify the parameters\Parameter1 #1#######\Parameter2 #2#######\Parameter3 #3#######
On top of your script place this code
ParameterInput.OPEN(Text1000000003)
ParameterInput.INPUT(1,Parameter1);
ParameterInput.INPUT(2,Parameter2);
ParameterInput.INPUT(3,Parameter3);
ParameterInput.CLOSE;
and then ofcourse the usual
Rec.setfilter(field1,parameter1);
Rec.setfilter(field2,Parameter2);
Rec.setfilter(field3,Parameter3);
etc etc.
and now you have your parameters.
If you want the window to open optionally you should place a condition before executing the above script;
Hope this helps0 -
Thanks.
I cannot use dialog (i shall use this codeunit within NAS so userinput is impossible). Optional parameters would have been 'nice to have', but I will find a way around..
- T.0 -
One way around is array of variant type variable and count of params in array passed into function... but no automatic type control etc...0
-
what's a problem?
Function(Param1,...,Var OptionParameter:option);
and return value into OptionParameter.keep it simple0 -
Polar wrote:what's a problem?
Function(Param1,...,Var OptionParameter:option);
and return value into OptionParameter.Definition: Function F(Param1,Param2,Param3); have possibility to call as: F(p1); F(p1,p2); F(p1,p2,p3);
something as calling MESSAGE(Text000), or MESSAGE(Text000,P1) etc...
[/code]0 -
kine, have you already solved a problem?
Unfortunatly, Navision is not object-oriented programming , but only based on it. :?keep it simple0 -
A working solution, but, it's .. not the best
Create a table, the fields are possible parameters (so you can have corrcet format)
On this table, you set a unique ID for each row.
When you call your function, you write the rox with your parameters, and give the unique ID to your function.
Your function retrieve row parameters (with ID) and work
...
I think it's the "best" solution with Navision0 -
I do love Navision,
Where with little exertion
And with extra-vision
You find through-ass solution.:P
keep it simple0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions