The error occurs due to the following line in the code:
switch app.selectedButton.Text
Here, 'selectedButton' is being referenced as a property of 'app' (app.selectedButton), but in the function, 'selectedButton' is defined as a local variable.
Therefore, the correct approach is to use the local variable directly, as:
switch selectedButton.Text
I hope this helps resolve the issue.