Is there a way to assign an object to a variable to make code easier to change and read? For example:
If(
IsBlank(txtItemSetupWidth.Text),
White,
If(
Or(
Value(txtItemSetupWidth.Text) < 0,
Not(IsNumeric(txtItemSetupWidth.Text))
),
ColorFade(
Red,
50%
),
White
)
)
in VBA I could do something like this:
With txtItemSetupWidth
If(
IsBlank(.Text),
White,
If(
Or(
Value(.Text) < 0,
Not(IsNumeric(.Text))
),
ColorFade(
Red,
50%
),
White
)
)
End With
Excel is also rolling this functionality in formulas with the new LET() function, but LET doesn't exist in PowerApps, and WITH() seems to do something totally different.
Solved! Go to Solution.
Hi @EdHansberry
Have you seen Shane Young's @Shanescows video about the PowerApps With() function?
Hi @EdHansberry
Have you seen Shane Young's @Shanescows video about the PowerApps With() function?
OnStart or OnVisible or OnSelect of a button Set a variable:
Set(Mycolor,txtItemSetupWidth.Text)
Then use the variable Mycolor to replace txtItemSetupWidth
------------
If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.
Thanks @Drrickryp . Definitely helpful. I'm still not getting it 100%. For example:
This works. If the text box isn't blank and has a positive and numeric value, it returns white, otherwise red.
With(
{TextBox: txtItemSellingUnitWidth.Text},
Switch(
true,
IsError(Value(TextBox)),
ColorFade(
Red,
50%
),
Value(TextBox) < 0,
ColorFade(
Red,
50%
),
Not(IsNumeric(TextBox)),
ColorFade(
Red,
50%
),
White
)
)
This next one though doesn't work. It is returning red, but it is a valid formula in the sense that PowerApps is evaluating it and returning red. I just need to dig into which of those is causing it, is it the value(TextBox.Text) isn't working or Not(IsNumeric(TextBox.Text)) isn't working.
In this example it doesn't matter, but it would if I wanted to evaluate different properties of the txtItemSellingUnitDepth object, not just the .Text property.
With(
{TextBox: txtItemSellingUnitDepth},
Switch(
true,
IsError(Value(TextBox.Text)),
ColorFade(
Red,
50%
),
Value(TextBox.Text) < 0,
ColorFade(
Red,
50%
),
Not(IsNumeric(TextBox.Text)),
ColorFade(
Red,
50%
),
White
)
)
It is this guy:
With(
{TextBox: txtItemSellingUnitDepth},
Value(TextBox.Text) )
If there is a numeric value in the text box, it still returns 0. Hrm... actually this returns false, so it isn't recognizing the numbers in the text box as numeric...
With(
{TextBox: txtItemSellingUnitDepth},
IsNumeric(TextBox.Text) )
User | Count |
---|---|
183 | |
105 | |
89 | |
44 | |
44 |
User | Count |
---|---|
226 | |
106 | |
106 | |
68 | |
67 |