Eval() function for Microsoft PowerApps - eval

Is someone aware of an equivalent function in PowerApps that will, just like the Excel Eval() function, take an input string value, execute commands specified within it, and produce a result? For example, if I have I have two variables, varOne already set to the value 1 and a variable x set to 8, and then I fed this Eval() function the following string:
"x + " & varOne & " = " & x + varOne
...it would produce:
"x + 1 = 9"
Does something like this (or a reasonable workaround) exist for PowerApps?

No, this functionality does not exist in PowerApps at this moment. Feel free to create a new feature request in the PowerApps Ideas board for this.

There are two ways to achieve this as of the moment.
Create a PCF Control and use JavaScript Eval().
You can use an Api like Math.js or even Bing Search on your Power Automate Flow to solve the equation for you.

$”x + {VarOne} “
This will generate x + 1 as output. You just need to add the Value(x) + Value(varOne) behind it.
It sort of does what you are looking for but not completely.
Via logic apps, you can create a JavaScript function and do eval there out of the box. That at least keeps it low code.

Related

Can't get Logic App Contains to work with array or comma separated string

I'm trying to look for specific keywords inside of text from a for each loop.
var text = "The lazy fox jumped over the brown dog."
var keywords = "fox,dog,sun";
If true, I want to do something with the text. If false, I want to ignore the text.
Does anyone know how to use an Array filter, Function, Select, Condition or inline code to check for this? If so, specific examples would be great.
By the way, I have a C# function that handles this extremely well in an ASP.net Core app.
UPDATE 1:
This doesn't work.
UPDATE 2:
The Condition is always false after the for each loop even after changing the settings and parallelism to 1.
Azure Logic App Condition does not work in loop if based on changing values
Thanks in advance!
There are so many ways to achieve what you need. Here are the 3 options that came to my mind within a minute.
The first one does use a For each loop, but I wouldn't recommend using it as it's not very efficient.
The For each parameter looks like this:
The Condition parameter looks like this:
The second option is much easier - no need for a loop, just filter the array straight away, then you can check whether it's empty or it has some items:
The Filter array parameters look as follows.
The split function is identical to the one used in option 1.
If you know JavaScript, you might decide to use regular expressions in inline code instead, e.g.:
Then you'd just need to check the output of the inline code. JavaScript code used in the example above:
var text = workflowContext.actions.Compose_text.outputs;
var keywords = workflowContext.actions.Compose_keywords.outputs;
return text.match(new RegExp("(" + keywords.split(",").join("|") + ")", "gi"));
My personal preference is option 2. However, please note that all 3 options above would find "sun" in text "The weather was sunny" even though there's no word "sun" in the text. If you do need "sun" to match only word "sun" - not "sunny", "asunder" or "unsung" - then go for option 3, just use a different, more complex regular expression.
One of the workaround would be use of Condition Connector. I have initialized the sentence in a string and then used Condition Connector which will be checking the conditions.
Finally, In the true section you can add the connectors accordingly.
Placing a Compose behind the for each loop and referencing the Output in the Condition is what finally worked for me. I used the toLower() function in my Compose. The Compose looks like this.
toLower(items('For_each_2')?['day']?['longPhrase'])

How do I add a variable to a piece of text?

I am creating a side scroller game, and I want a counter on the UI that counts how many times the player has died. But, I do not know what to add to what I have already. I tried typing the variable name behind the &, but it did not accept that. What do I do to put a variable in a set of text?
I am using the free version.
The & is the string concatenation operator in Construct 2.
For global variables:
"Deaths: " & VARIABLE_NAME
For instance variables:
"Deaths: " & instanceName.variableName
Note the " around the string.
NB: There is no need to explicitly convert the number to a string, it will be done implicitly.
Construct-2 runs on Javascript, so would the "+" operator not do what you are attempting?

is it possible to pass a single id value as an object to an event in angular

First day using angular so gonna ask a really simple question.
I have a simple event that I want to respond to a click. Currently, it is written in jQuery but seems like it should be able to be done in angular. I have:
str="<div ng-click='sayHello(" + global_id.to_s + ")' class='add-as-favorite arc-favorite' data-type='" + type + "' data-global-id='" + global_id.to_s + "'> </div>"
I am trying to simulate in plunkr (first time using) here: http://plnkr.co/edit/wytErhWDDu9Qh66M7JrX but I can't even get this to work.
I think this is not working because I am passing the integer value here. The reason is that as a string is because it is in a helper (which may or may not be affecting it). Also, we have about 10 of these on a single page which, again, may or may not be affecting it. I really just want to pass this global_id value to the sayHello function. Is this possible?
thx
You had a typo (ng-controller had an extra ' and was missing the closing "). Here's your plnkr fixed: http://plnkr.co/edit/LyErnFyzjraPOumyKxJD?p=preview

WPF Binding.StringFormat: C vs. '{}{0:C}'

I am trying to globalize a simple WPF app. In several questions and/or answers on SO I see one of the following two settings on the binding:
StringFormat=C
StringFormat='{}{0:C}'
What is the difference between these? Are there certain conditions where you would use one over the other?
My understanding is that there is no difference, one is just shorthand and the other explicit. The only condition I can think of where being explicit is beneficial is when you want more control over the format. For example:
StringFormat=Total: {0:C}
Other than that, I'd say keep it simple; XAML is already verbose and shorthand syntax is welcome.
Maybe read up string formatting?
http://msdn.microsoft.com/en-us/library/dd465121.aspx
You can use {0:C} in a format string where you are filling in a value:
decimal value = 123.456;
Console.WriteLine("Your account balance is {0:C2}.", value);
while, you use the C as a plain format:
Console.WriteLine(("Your account balance is " + decimal.Parse("24.3200").ToString("C"));
they are functionally equivalent as far as the output. It's just a different way to format the data based on the context of how your using it.
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx#CFormatString

Linq Querying for user search

I am trying to query from search box using list of data and the linq I used is:
data = (From k As BSPLib.ContactLib.Contact In data_org.Values Where k.stringdata Like "%" & Searchtxtbox.Text & "%" Select k.prime).ToList
But this is not working, I am getting no data at all. Data_org is a dictionary so I used the values; k.stringdata contains all the data that need to be searched. Searchtxtbox.text contains the user defined search item.
I Tried with sqlmethods through linq, but sqlmethods does not exist for me, I tried with with Imported namespace yet the code is not showing sql methods, could you please provide a workable query or just tell me where I have gone wrong. Thank you.
My Visual Basic is a bit rusty so forgive me if I have the syntax wrong:
One thing you could use is Contains which will be similar to "%Searchtxtbox.Text%"
and exactly the same if it is used with a DatabaseContext.
I know it is not the same as Like but if that doesn't work than likely something else is wrong and than I would like more code.
data = (From k As BSPLib.ContactLib.Contact In data_org.Values Where k.stringdata.Contains(Searchtxtbox.Text) Select k.prime).ToList
You can additionally use StartsWith and EndsWith for "Searchtxtbox.Text%" and "%Searchtxtbox.Text"
Also would I like to suggest to puth "%" & Searchtxtbox.Text & "%" between Parentheses for clarification, but that's all up to you.
The % wildcard character won't work here, remember this is .NET code, not SQL. You need something like this instead:
data = (
From k As BSPLib.ContactLib.Contact In data_org.Values
Where k.stringdata.Contains(Searchtxtbox.Text) Select k.prime).ToList

Resources