Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
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

Please add me Anil_Babu_Samineni to interact faster when reply back. Speak low think High.

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
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