Skip to content

Switch blocks #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
djaus2 opened this issue Mar 25, 2025 · 9 comments
Open

Switch blocks #177

djaus2 opened this issue Mar 25, 2025 · 9 comments

Comments

@djaus2
Copy link

djaus2 commented Mar 25, 2025

Unless there is already a way, it would be nice to have switch blocks based upon ordinals. Supposed one issue might be the number of switches.
Today I implemented the equivalent with nested if then else blocks.
Keep up the good work! 👍

@ignatandrei
Copy link
Owner

I am not sure that I understand what it says. Could you please give an example ?

@djaus2
Copy link
Author

djaus2 commented Mar 25, 2025

Image
An example

@djaus2 djaus2 closed this as completed Mar 25, 2025
@djaus2
Copy link
Author

djaus2 commented Mar 25, 2025

Didn't mean to close this.

@ignatandrei
Copy link
Owner

I understand now. Thinking....

@ignatandrei ignatandrei reopened this Mar 26, 2025
@djaus2
Copy link
Author

djaus2 commented Mar 26, 2025

Thx for reopenning this and considering it.
I have worked out a work around for now, not yet implemented.
I can add a new ASP.NET controller method that takes a csv list of ordinals for the required commands along with the menu parameter which implements the switch-case funstionality there. ... The "beauty of being able to adhocly add more controller methords..

Even better, take the string at the start of the block above and look up the command names using the menu parameter and call that comamnd.
The new version of Softata NetCporeBlockly has lookup capability for commands.

Nb: For simplicity, the lookup selects the named command that either contains the part of the csv string when split into its components or the commnd name that is contained in the lookup value._ A "lazy" search.

@djaus2
Copy link
Author

djaus2 commented Mar 26, 2025

The latter was simple to implement:

        public IActionResult ActionDeviceCmdindexfrmCSVlistNoParam(DeviceInstance deviceInstance, string csv, byte index)
        {
            string[] cmds = csv.Split(',');
            if (index >= cmds.Length)
            {
                return BadRequest("Index out of range");
            }
            byte subCmd = LookUpGenericCmd(deviceInstance.DeviceType, cmds[index]);
            string result = sharedService.ActionDeviceCmdwithByteArrayParams((int)deviceInstance.DeviceType, HttpContext, Client, deviceInstance.ListLinkId, subCmd);
            return Ok(result);
        }

Is only a few obvious lines different from ActionDeviceCmdNoParam()
Actually it's a little more complex, (not shown here) but only marginally, because the csv string has a colon seperated part at start for the menu heading.

switch-case would be useful in the longer term though, but I understand it could be complex.

@djaus2
Copy link
Author

djaus2 commented Mar 26, 2025

Here are the blocks thus (implemented with 2nd scenario):

Image

@djaus2
Copy link
Author

djaus2 commented Mar 26, 2025

Comment.
Note found that variables used in a function are global.
Hence menu2 as menu is in the Menu with MenuCSV() function etc.
Might be "nice" if function variables weren't gobal

@djaus2
Copy link
Author

djaus2 commented Mar 26, 2025

Oh I see that the following block can do it, I think.
Once I figured out how to and more cases:

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants