Is there a way to add comments to a code set or a code line?
Solved! Go to Solution.
There's no way to comment code directly in the formulas. One workaround that I've used for complex formulas is to break it down in components (using context variables), and use some If(false) statements that do nothing except to allow for some information to be added. For example, in the app below, the expression button used to calculate the roots for the equation is a little complicated:
I could have a single expression to calculate both roots, but that would be quite complex:
UpdateContext({ root1: If(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text) < 0, 0/0, (-Value(TextInputB.Text)+Sqrt(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text)))/(2*Value(TextInputA.Text))), root2: If(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text) <= 0, 0/0, (-Value(TextInputB.Text)-Sqrt(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text)))/(2*Value(TextInputA.Text))) })
If I break it down into sub-expressions, I can interpolate some "comments" to make it more readable:
If(false, "Save control values in variables for easier manipulation"); UpdateContext({a:Value(TextInputA.Text), b:Value(TextInputB.Text), c:Value(TextInputC.Text)}); If(false, "Calculate the value for the discriminant"); UpdateContext({delta: b*b - 4*a*c}); If(false, "Calculate the roots"); UpdateContext({ root1: If(delta < 0, 0/0, (-b+Sqrt(delta))/(2*a)), root2: If(delta <= 0, 0/0, (-b-Sqrt(delta))/(2*a)) })
Hi everybody,
I have learned another way you can include comments. Normally you chain actions with a semi-colon. But you could also write text where an action would go, then set it off with a semi-colon. It won't do anything, but it provides the comment you want.
Example:
"Add 1 to the current score each time you press the button"; Set(score,score+1)
Here's another example of it in practice:
https://youtu.be/j30xOM5OmRE?t=7m57s
@Anonymous @CarlosFigueira @ManishM
This is great! Thank you MSFT for the feature and @DavesTechTips for notifying.
There's no way to comment code directly in the formulas. One workaround that I've used for complex formulas is to break it down in components (using context variables), and use some If(false) statements that do nothing except to allow for some information to be added. For example, in the app below, the expression button used to calculate the roots for the equation is a little complicated:
I could have a single expression to calculate both roots, but that would be quite complex:
UpdateContext({ root1: If(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text) < 0, 0/0, (-Value(TextInputB.Text)+Sqrt(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text)))/(2*Value(TextInputA.Text))), root2: If(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text) <= 0, 0/0, (-Value(TextInputB.Text)-Sqrt(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text)))/(2*Value(TextInputA.Text))) })
If I break it down into sub-expressions, I can interpolate some "comments" to make it more readable:
If(false, "Save control values in variables for easier manipulation"); UpdateContext({a:Value(TextInputA.Text), b:Value(TextInputB.Text), c:Value(TextInputC.Text)}); If(false, "Calculate the value for the discriminant"); UpdateContext({delta: b*b - 4*a*c}); If(false, "Calculate the roots"); UpdateContext({ root1: If(delta < 0, 0/0, (-b+Sqrt(delta))/(2*a)), root2: If(delta <= 0, 0/0, (-b-Sqrt(delta))/(2*a)) })
@CarlosFigueira Thanks for the workaround solution . It is time for the Dev team to add the ability to comment code in a direct way.
Something I've just started to use thanks to the new global var Set() function is e.g.
Set(c_icn_Save_Props_OnSelect,"### TODO: Some comment here ###")
... note the "c_" prefix for comments and a name to reflect the object/method (debatable usage esp. if object name is changed!) .
I can then review-and link to-all of my comments from one place (the Variables (Experimental) tab).
@CarlosFigueira thank for the workaround! That is very clever!
One thing that worries me though, wouldn't these ifs add more load on the app when we are talking about complex apps with multiple screens and complicated formulas?
Hi everybody,
I have learned another way you can include comments. Normally you chain actions with a semi-colon. But you could also write text where an action would go, then set it off with a semi-colon. It won't do anything, but it provides the comment you want.
Example:
"Add 1 to the current score each time you press the button"; Set(score,score+1)
Here's another example of it in practice:
https://youtu.be/j30xOM5OmRE?t=7m57s
@Anonymous @CarlosFigueira @ManishM
Thanks for sharing. I will definitely try that. However I just hope that all this workarounds for comments will not stop PG to implement proper comments in the code
Don't worry, it will not stop the team from implementing comments - it should be coming soon. Thanks for the feedback!
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
User | Count |
---|---|
199 | |
52 | |
41 | |
39 | |
35 |
User | Count |
---|---|
263 | |
86 | |
71 | |
69 | |
66 |