Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
I would like to assign an output of a function to a variable.
Say a function is just
function test
test = 3 + 3
end function
While trying to assign to a variable, say, vTestVar, I get an error message:
Error: Error in expression: TEST ist not a valid function.
What am I doing wrong?
Thank you very much in advance.
You need to add () after the function name
function test ()
test = 3 + 3
end function
And set the variable in your load script thus, not forgetting the (), I also put a trace after it to display what is in the variable.
let vTestVar = test() ;
trace vTestVar: $(vTestVar) ;
Sample qvw is attached.
Where you use this function on the load script or some where else.
Regards
Anand
Thank you for your response, Anand!
I define the function in the module and then try to assign its output to a variable either in UI or in the load script. Neither works.
For more details for this please check the Qlik API Guide.
Regards
Anand
Personally I avoid macros, the reasons are explained in this Blog Post Macros are Bad
Notwithstanding that, what are you trying to achieve with this macro ?
It may be achievable without resorting to a macro.
Thanks Bill,
I am also agree with you and this macros are time consuming also.
@qv_mypath You can do this with normal tables also with the inline data i represent a small demo to you to explain how to do this calculation with the tables.
//Calculation Done on the Variable
Let vTest = 3 + 3;
//Variable calculation taken on the table
Load * Inline
[
Addition_Result
'$(vTest)'
];
You can do any calculation on the script part.
Regards,
Anand
Thank you for your response, Bill!
I asked this more to learn about the general possibility (to define any function in macro module and to assign its output to any variable - preferably in UI but at least in the load script). The certain goal can surely be achieved without macro 🙂
That said, I am agree that the macros are somewhat less than perfect. But sometimes you need a user-defined function. The best example I can think of at the moment is borrowing functions for regex processing from vbs since you do not have them in the load script out of the box.
You need to add () after the function name
function test ()
test = 3 + 3
end function
And set the variable in your load script thus, not forgetting the (), I also put a trace after it to display what is in the variable.
let vTestVar = test() ;
trace vTestVar: $(vTestVar) ;
Sample qvw is attached.
Thank you very much! This did the trick for the sample function.