Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
pradeep92
Partner - Creator II
Partner - Creator II

SET EVALUATE

hi,


I have specified Set x=3+4; in script and when i evaluate as =$(x) in text box, it gives 7.Why is that so ?

1 Solution

Accepted Solutions
Peter_Cammaert
Partner - Champion III
Partner - Champion III

The different engines involved act like that because of two simple reasons:

  • text literal assignment (scripting engine), and
  • text substitution (expression evaluator)

A SET statement assigns the right hand part as-is to the variable specified in the left hand part. So x will contain string '3+4'.

Now in the expression, the evaluator will perform $-sign substitution first, before doing anything else. That gets the original expression =$(x) converted into =3+4 after which the expression is finally evaluated and produces a fixed value of 7. That one gets displayed.

Note that what applies to the expression with respect to $-sign substitution always coming first, also applies to the right-hand part of the SET statement. $-sign substitution in the right-hand part of a SET statement will be applied even before the scripting engine tries to figure out what statement it is looking at. And that's the main reason why stuff like the following even works at all !

SET y = SET;

$(y) x = 3+4;

If this explanation is unclear, please ask away.

Best,

Peter

View solution in original post

4 Replies
Clever_Anjos
Employee
Employee

It seems to be correct to me, what do you see as wrong?

What do you expect to see?

prma7799
Master III
Master III

What is your required output?

Anil_Babu_Samineni

Off course, Because you are computing using $() indicator. Remove that and check with simple x ??

Set x=3+4; //vVar has the expression 2+3 as value we have to compute it using $(vVar) which returns 5

Let x=3+4; //vVar has the computed value 5

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Peter_Cammaert
Partner - Champion III
Partner - Champion III

The different engines involved act like that because of two simple reasons:

  • text literal assignment (scripting engine), and
  • text substitution (expression evaluator)

A SET statement assigns the right hand part as-is to the variable specified in the left hand part. So x will contain string '3+4'.

Now in the expression, the evaluator will perform $-sign substitution first, before doing anything else. That gets the original expression =$(x) converted into =3+4 after which the expression is finally evaluated and produces a fixed value of 7. That one gets displayed.

Note that what applies to the expression with respect to $-sign substitution always coming first, also applies to the right-hand part of the SET statement. $-sign substitution in the right-hand part of a SET statement will be applied even before the scripting engine tries to figure out what statement it is looking at. And that's the main reason why stuff like the following even works at all !

SET y = SET;

$(y) x = 3+4;

If this explanation is unclear, please ask away.

Best,

Peter