BDavisNJ Posted May 15 Share Posted May 15 I find that ComposerPro (HE) is missing a logic command equivalent to the CASE function in Excel's VBA. Consider an instance in which you want a singular event to be triggered when a button is pressed and the brightness of a particular light is within a set of ranges. For example: CASE LL Bedroom-->Entry is on <AND> if LL Bedroom->Entry current brightness <=25% Set the brightness to 25 on LL Bedroom -> Entry LL Bedroom-->Entry is on <AND> if LL Bedroom->Entry current brightness <=50% Set the brightness to 50 on LL Bedroom -> Entry LL Bedroom-->Entry is on <AND> if LL Bedroom->Entry current brightness <=75% Set the brightness to 75 on LL Bedroom -> Entry LL Bedroom-->Entry is on <AND> if LL Bedroom->Entry current brightness <=100% Set the brightness to 100 on LL Bedroom -> Entry additional code follows.... Yes, a set of STOP or ELSE commands can be used but not very efficiently. I also would propose either a SUBroutine or GOTO command for additional flexibility. Thoughts appreciated. Quote Link to comment Share on other sites More sharing options...
Popolou Posted May 15 Share Posted May 15 I think the devs didn't ever consider it to that extent especially when they allowed for nested IFs to begin with. It would be a lot easier if there was such a function and i agree, it would be a helpful addition. The marginally cleaner way would be to use a WHILE statement (ie for when the light is on) but that does little to improve the efficiency overall. A GOTO or a 'jump to' function was an obvious one that i was also surprised was not added in. Someone over there must have played around with BASIC when they were younger right? By the way, i am sure your example was purely that but i think you'd need some lower limits as well to those AND statements. Quote Link to comment Share on other sites More sharing options...
Cyknight Posted May 15 Share Posted May 15 While I appreciate the method myself, I suspect that for most adding a CASE command will be just more confusing than creating a macro to trigger that uses the basic stop and buried if statements WHEN button is pressed IF Light bightness >0 IF brightness <25 set to 25 stop IF brightness <50 set to 50 stop etc More options is not ALWAYS better. Neo1738 1 Quote Link to comment Share on other sites More sharing options...
RAV Posted May 15 Share Posted May 15 If Bedroom is on, run macro BedLevel Macro BedLevel If light is <25, set light to 25, stop If light is <50, set light to 50, stop if light is <75, set light to 75, stop Set light to 100 Lots of ways to skin the cat. Above feels like same or less amount of code as a CASE. Quote Link to comment Share on other sites More sharing options...
BDavisNJ Posted May 15 Author Share Posted May 15 thank you for your reply. I will count another vote in favor of adding GOTO and CASE. With respect to your comment regarding lower limits, in the VBA world, each of the conditionals listed under CASE would be considered in order; once ONE of the conditionals were true, the <then> portion would be executed AND the operating system would jump to the additional code -- the other conditionals of the CASE command would not be considered. By listing the conditionals in ascending order, we can eliminate the lower bounds. This is very efficient. Quote Link to comment Share on other sites More sharing options...
Cyknight Posted May 15 Share Posted May 15 11 minutes ago, Popolou said: Someone over there must have played around with BASIC when they were younger right? More or less as per above, I think the issue was never the people creating the program, but the people they were creating the program for. MOST (field) programmers for C4 aren't IT trained or even hobbyist. Let alone the end-user using HE. Sure the upcoming generation of starting tech may have a much higher knowledge of programming terminology, but most that are now doing it needed to even learn the principal of what an IF statement is to begin with. C4's goal was/is (I believe) to ensure the programming software is as accessible as possible. Of course, the base software is about 2 decades old at this point and has been pushed far beyond it's initial boundaries to begin with. Perhaps by OS 4/5 there will just have to be a new 'Composer' to begin with: but it will likely require a full new training setup and for all programmers/dealers to get re-certified. Not against that myself - but I can't help but wonder at the failure rate of that re-certification (for better or worse...) Quote Link to comment Share on other sites More sharing options...
Popolou Posted May 15 Share Posted May 15 @Cyknight Agree entirely and this discussion is quite timely because i recently got buried into some complex nested IF and WHILE statements which was rather exhausting once completed. However, it made me wonder about this very same discussion and how they could have adopted a little from here and there of all the different programming routines that are commonly used. In my view, the OP is on to a point and where surely an evolution of all these nested IF statements is simply a single use of CASE. Quote Link to comment Share on other sites More sharing options...
RAV Posted May 15 Share Posted May 15 I recall a stat once that I heard less than 20% of projects have ANY code in the programming tab. Control4 did a road tour education to highlight things like basic motion triggers. So yeah, the bar is very low. Everyone here is the exception. Popolou 1 Quote Link to comment Share on other sites More sharing options...
Popolou Posted May 15 Share Posted May 15 21 minutes ago, BDavisNJ said: By listing the conditionals in ascending order, we can eliminate the lower bounds. This is very efficient. Interesting, my gut is telling me that this won't happen with Composer's programming and without lower bounds, you will need to add a BREAK after each successful validation & match so that it exits that routine to then process any subsequent code. Or a STOP if that is all there is. Quote Link to comment Share on other sites More sharing options...
BDavisNJ Posted May 15 Author Share Posted May 15 First thank you all for your comments. This forum is a tremendous resource. By way of follow-up, I wanted to post the code that is successfully working in my project. I have attached the screenshot. I am not using STOP commands because my use case requires that when a KCB button marked "Brighter" is pressed, all of the 4 lighting circuits that service a room get brighter <IF> that particular lighting circuit is already on. If the lighting circuit is off, the button press has no impact on that circuit. Many experienced C4 programmers are on this board. I invite / welcome all comments, criticisms, and suggestions. Quote Link to comment Share on other sites More sharing options...
RAV Posted May 15 Share Posted May 15 You could do: You'd reduce that to 4 lines: If entry is on set entry brightness percent +25 If bed If desk If center Quote Link to comment Share on other sites More sharing options...
Popolou Posted May 15 Share Posted May 15 @BDavisNJ I suppose you could find that some of the lights may be out of sync with the remainder on the circuit when it is pressed? Glad to see the use of ELSE, it is often left out which is sacrilegious Quote Link to comment Share on other sites More sharing options...
BDavisNJ Posted May 15 Author Share Posted May 15 @RAVfantastic! yup, I agree with your approach. Thank you for sharing. Quote Link to comment Share on other sites More sharing options...
BDavisNJ Posted May 15 Author Share Posted May 15 @RAV Below is the dimming code post your suggestion ... Quote Link to comment Share on other sites More sharing options...
RAV Posted May 15 Share Posted May 15 You may want to bump up your <=20 to be <=35. If it's at 21, you'd end up at 1, not 15 which I interpreted is your target minimum? I prefer to nest under the if on, as the indents show a logical progression, do the first indent else the second, just how I visualize programming personally. Neo1738 1 Quote Link to comment Share on other sites More sharing options...
BDavisNJ Posted May 15 Author Share Posted May 15 @RAV 100% agree with both of your points; I have revised my code and appreciate your commentary. I learned some today and I hope others reviewing these notes are equally benefited. Thank you. Quote Link to comment Share on other sites More sharing options...
zaphod Posted May 16 Share Posted May 16 I find programming in C4 very awkward, inefficient and slow since you are clicking on various windows and having to scroll down in quite small little windows. And the way that lists are handle seems inconsistent. Like when you are programming with macros you select the macro from a dropdown list, but the list of Scheduler Events are all displayed in a full list. And some of the lists you can reorder, or sort by name, but others seem to be permanently fixed with the order that they were created. They really should clean this up and make it more friendly to real programmers, especially since we are now in an age where AI can help you code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.