Hello everyone,
I am building an app and have many screens (approx. 50) half of which will use the same code to navigate to the next screen. Problem is the different options for this navigation will change and increase over time so I need to have the code in one place so I can update all screens with one change.... so reuse the code.
I have looked at using the toggle button but other posts state that this isn't the best solution and often causes errors.
Therefore, I would like to use a component, is this possible by just calling a variable which triggers the component and executes the code?
Pasted in below is the code I want to use:
Set(NextCount, Switch(ProdDirOut,
"Prod1",
First(Sort(Filter(Prod1, OpCode01 > CurrCount), OpCode01)).OpCode01,
"Prod2",
First(Sort(Filter(Prod2, OpCode01 > CurrCount), OpCode01)).OpCode01,
"Trial",
First(Sort(Filter(Trial, OpCode01 > CurrCount), OpCode01)).OpCode01
)
);
Set(NextStep, Switch(ProdDirOut,
"Prod1",
LookUp(Prod1, OpCode01 = Value(NextCount), Step),
"Prod2",
LookUp(Prod2, OpCode01 = Value(NextCount), Step),
"Trial",
LookUp(Trial, OpCode01 = Value(NextCount), Step)
));
I watched a couple of online lessons on components, but they don't cover code reuse via variables.
Thanks for your help.
Rob
Thanks for the advice but the app just updates a tracking gallery and all other data is patched out so it shouldn't be too slow.
Hey @rob4681
I usually use containers and variables to minimize the number of screens.
I would really suggest not to use 50 screens, this will decrease the application speed and it wont be user friendly.
So I would suggest the following technique:
1) Add a horizontal container.
2) Inside that add a normal container. [You can keep its height and width according to outside container].
3) On the press of buttons you can make global variables that would turn true or false.
4) Make OnVisible Property of the outside container according to those variables.
Adding screenshots below:
Here is my container 4 that contains all the things related to appointments:
If you see above, OnVisible Property of the container is varAppoint.
On the OnSelect property of the Appointments button I have added the following code:
Set(varAppoint,true);Set(varBranch,false)
So, when I press the button, it would make the Appointment container visible.
Now coming to the Branches Container:
If you see OnVisible Property of the container, I have added varBranch.
Then on the OnSelect Property of the Branches Button I have added:
Set(varAppoint,false);Set(varBranch,true)
Now sometimes this does not work initially so what I do is, on the OnVisible Property of the screen, by default I will make the varAppoint as true and varBranch as false. So whenever the screen is loaded, the Appointments container would be visible. Because initially when you start the app, the variables would have a blank value. So, whenever the screen loads it will show you Appointment container defaultly. Or if you dont want this, you can also make the variable true or false on the OnStart Property of the application.
So by the above approach you can decrease the number of screens, and I would highly suggest this approach. Making 50 screens is really too much.
I hope this helps 🙂