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
Power Apps Africa Challenge 2022

Power Apps Africa Challenge

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

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Government Carousel

New forum: GCC, GCCH, DoD - Federal App Makers (FAM)

In response to the unique and evolving requirements of the United States public sector, Microsoft has created Power Apps US Government.

Users online (5,288)