cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
datapawn
Frequent Visitor

Switch Function

I'm trying to create a simple UI that will change the color of a Rectangle control when it is clicked on.

I'm Set 5 of our brand colors as global variables.

I'm trying to figure out why this switch statement only toggles back and forth between the first two colors?

Switch(
CurrentColor = ard_Black,
Set(
CurrentColor,
ard_Gray
),
CurrentColor = ard_Blue,
Set(
CurrentColor,
ard_Orange
),
CurrentColor = ard_Gray,
Set(
CurrentColor,
ard_Blue
),
CurrentColor = ard_Orange,
Set(
CurrentColor,
ard_Purple
),
CurrentColor = ard_Purple,
Set(
CurrentColor,
ard_Black
)
);

 

4 REPLIES 4
avootla1
Frequent Visitor

@datapawn 

 

The switch syntax is incorrect. Here's how it should look like

 

Switch( test.Value, somevalue, "Result1", somevalue1, "Result2", somevalue2, "Result3")

avootla1
Frequent Visitor

@datapawn 

 

Here's how your switch statement should be

 

Switch(
CurrentColor,
ard_Black,
Set(
CurrentColor,
ard_Gray
),
ard_Blue,
Set(
CurrentColor,
ard_Orange
),
ard_Gray,
Set(
CurrentColor,
ard_Blue
),
ard_Orange,
Set(
CurrentColor,
ard_Purple
),
ard_Purple,
Set(
CurrentColor,
ard_Black
)
);
datapawn
Frequent Visitor

I have tried that and it is still not working.

I should have also noted, at the app startup i Set(CurrentColor, ard_Black) - not sure if that clears up why i was attempting to do CurrentColor = ard_Black as my test.Value.


I'm having trouble understanding the syntax - what is somevalue?

avootla1
Frequent Visitor

@datapawn if you want to change the color of the rectangle on click, there is an other way to do it. In the above syntax, you are comparing CurrentColor and setting a new value which leads to ambiguity. 

 

Use PressedFill property to change the Fill color value of the rectangle on click.

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Users online (2,629)