Using variant parameter with var check

Cem_Karaer
Member Posts: 281
Hello,
I want to create a generic function that will accept any type of variable as a first parameter and a text variable parameter. The text parameter will be tried to be evaluated to the type of the first parameter.
For example:
TestFunction(DateVariable,'13.02.2012')
DateVariable should be set to 13022012D
TestFunction(IntegerVariable,'345')
IntegerVariable should be set to 345
ect..
For this I defined the first parameter as variant and worked as desired. But because it is not a var variable, I cannot get the evaluated value outside TestFunction. So I defined it as var, but NAV wants only variant type in this case.
Is it a solvable problem or restrictions of NAV prevent such a generic functionality?
I want to create a generic function that will accept any type of variable as a first parameter and a text variable parameter. The text parameter will be tried to be evaluated to the type of the first parameter.
For example:
TestFunction(DateVariable,'13.02.2012')
DateVariable should be set to 13022012D
TestFunction(IntegerVariable,'345')
IntegerVariable should be set to 345
ect..
For this I defined the first parameter as variant and worked as desired. But because it is not a var variable, I cannot get the evaluated value outside TestFunction. So I defined it as var, but NAV wants only variant type in this case.
Is it a solvable problem or restrictions of NAV prevent such a generic functionality?
Cem Karaer @ Pargesoft
Dynamics NAV Developer since 2005
Dynamics NAV Developer since 2005
0
Comments
-
Something like this:
CASE TestFunction('13.45') of 'DECIMAL': SomeDecimal := ResultFunctionDecimal(); 'INTEGER': SomeInteger := ResultFunctionInteger(); ... END;
In TestFunction you have something likeFUNCTION TestFunction(...) BEGIN ... DecimalValue := ....; //DecimalValue is a GLOBAL variable END;
FUNCTION ResultFunctionDecimal() BEGIN EXIT(DecimalValue); END;
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Could use the "original" variant data type - a string
Something like:TestFunction(MyVar : Variant) : Text[200] BEGIN ... do stuff with variant ... EXIT(FORMAT(MyVar)); END; // call function like: EVALUATE(MyInt, TestFunction(1234)); EVALUATE(MyText, TestFunction('Some Text')); // or MyInt := 1234; EVALUATE(MyInt, TestFunction(MyInt)); ... etc.
0 -
Just use a FilterField in a table of the correct type, it will correctly evaluate text to the required format.David Singleton0
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