Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Do While syntax bug

on a number of occations i have had to change the syntax of using a variable in the condition part of a do while loop.

on some occations $(varName) is needed, some cases '$(varName)' is needed, some cases varName is needed (and appears in red [feild]?) and in some cases 'varName' is needed.

just something which could be improved on

thanks for your consideration

rhys bradbury

6 Replies
Not applicable
Author

BUMP for QV R+D team to see

jonathandienst
Partner - Champion III
Partner - Champion III

Rhys

These all mean different things. Let me attempt to explain them:

  • $(varName)   - returns the expansion of the variable (performed before the statement is executed). This is the same as typing the contents of the variable. If the contents are an expression, it will be evaluated when the statement is executed. You can use this form when the variable is defined (for example):
      • Set v1 = 2; (2, evaluated, returns 2)
      • Set v2 = Count(Distinct ClientID); injects this expression fragment which is evaluated when the statement or expression is executed.

  • '$(varName)'  - also return the expansion, but treats the contents as a string. In other word, when the statement is executed, the variable's content will be placed in the string and not evaluated. For example, if variable v1 contains 2012/10/26, then
      • $(v1) will result in 2012 divided by 10, divided by 26 (7.7385)
      • '$(v1)' will result in the string '2012/10/26'

  • varName - returns the value of the variable (like a conventional variable in other programming languages). You can use this form when the variable is defined as (for example):
      • Set v1 = 2;
      • Set v2 = =Count(Distinct ClientID); (returns the pre-evaluated expression. Note the 2 = symbols)
      • you cannot use this form in a LOAD or SELECT statement - it will be interpreted as a field name.

  • 'varName' - will simply return a string containing 'varName', and makes no reference to the variable at all.

Hope that helps to clear up the situation.

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Thankyou for such a comprehensive reply, this is very useful knowledge and i will be using this as a reference when dealing with syntax from now on.

Thankyou once again,

Rhys Bradbury

jonathandienst
Partner - Champion III
Partner - Champion III

Rhys

You're welcome. Perhaps this sort of thing should be in a tutorial manual

Regards

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Agreed

Not applicable
Author

I just liked this answer... it's hugely helpful! I wish I could do more than just like it... give it stars, and banners, and awards.

This explanation needs to be easier to find!