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
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (1,752)