SELECT CASES ??? - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2) +--- Thread: SELECT CASES ??? (/showthread.php?tid=978) |
RE: SELECT CASES ??? - Kernelpanic - 10-16-2022 (10-16-2022, 10:28 PM)Pete Wrote:(10-16-2022, 09:57 PM)SMcNeill Wrote: If it's a FUNCTION, then doesn't it need a return variable associated with it? Unfortunately that didn't work at all. There's the database, and I've changed the "Sub" to a function so that it returns the specified record number. The corresponding motorcycle should then be shown for each set number. I couldn't find anything on the net about a function in a Select ... Case query. If it works with a sub, it must also work with a function, right? What kind of error is there just a complaint? Code: (Select All) $Console:Only RE: SELECT CASES ??? - SpriggsySpriggs - 10-16-2022 YIKES! RE: SELECT CASES ??? - Pete - 10-16-2022 The point being you can't just call a function like you do a sub. Frankly, I'd just change the function to a sub, and define SatzLesen or drop it and just pass back SatzNummer. The PRINT SatzLesen wasn't meant s a solution, it was just an example of using a function in QB64 without anything being returned. In general, functions either must return a value or have an active part in a statement like foo = SatzLesen or foo = Steve \ SatzLesen, etc. So for subs, just call them. For functions, have something returned involved in the call statement, and not just the call alone. Pete RE: SELECT CASES ??? - SMcNeill - 10-17-2022 I'd try removing these three lines as they're not needed: Code: (Select All) Declare Sub Eingabe() Honestly, that last line looks wrong to me. I don't think that 0 needs to be in there. RE: SELECT CASES ??? - Pete - 10-17-2022 DECLARE statements are just ignored in QB64. Left over QBasic stuff. Pete RE: SELECT CASES ??? - SpriggsySpriggs - 10-17-2022 You can declare a function and sub with the same name RE: SELECT CASES ??? - dbox - 10-17-2022 (10-16-2022, 09:23 PM)SMcNeill Wrote:(10-16-2022, 09:12 PM)Pete Wrote: Two votes for cool, 1 vote yuck. Cool wins. When can we expect the roll out??? So are you saying... (10-11-2022, 03:38 PM)SMcNeill Wrote: "Hey, I personally don't need X feature, so it's a waste to include it in the language!" RE: SELECT CASES ??? - SMcNeill - 10-17-2022 @dbox Aye, that's my opinion, just as other folks find other features and additions to be a waste. Everyone is entitled to their opinion, and, as an open source project, everyone is free to work on the project and develop new syntax and capabilities. As I mentioned, I don't think any of the existing developers are going to implement such a syntax into the language for three main reasons: 1) This syntax can already be accounted for, almost letter by letter, simply by using existing IF THEN statements. 2) The proposed syntax is both wordier and more inefficient than the existing method. 3) The developers we have are all volunteers who work to *improve* the language in their spare time. This change doesn't improve anything. But, with that said, I'd encourage Pete -- or whomever wants to, including you -- to work up the changes yourself and push them into the repo. We always try and support new developers, and this really doesn't seem like it'd be overly complicated for someone to use as a break-in exercise to learning and interacting with the qb64pe.bas source. Just because none of the current devs would be interested in spending their precious free time to add or make a suggested alteration, that doesn't mean you can't make it yourself. *That's* the beauty of open-source programming. RE: SELECT CASES ??? - DSMan195276 - 10-17-2022 Personally I do actually like this kind of syntax, C# has similar functionality via doing a switch()(equivalent of SELECT CASE) on a 'tuple' value (which is basically just a variable that holds multiple other variables). You can then have cases like case (> 0, < 20)where the first and second values in the tuple have to match those conditions. I've used it a few times and it makes it very easy to read the actual conditions you're checking for vs. having nested switch()or a bunch of ifstatements. I will say that it has some downsides. It's a nice syntax in terms of being easy to read, but in my experience it makes it a bit harder to verify that all possible cases are actually covered (since the possible combinations quickly balloons). Additionally IMO performance isn't a huge concern. A "good" compiler would be capable of optimizing this statement such that it doesn't matter how you write it. QB64 is not there, so certainly there's a potential performance penalty due to the likely multiple comparisons used to implement it, but IMO not enough to really matter anyway for most people. That is also something that could potentially be improved in the future sometime after the command is added. That said, echoing what Steve said a bit, I can't pretend I have enough time to look at implementing something like this, I have too much I'm trying to get done already XD If someone was interested though I'd encourage them to submit a proposal on GitHub and we could talk about potential syntax and such (I don't think the syntax Pete gave would quite work). RE: SELECT CASES ??? - Pete - 10-17-2022 It's been what, 6 or 7 years since I wrote a key input routine in C. I vaguely remember using the SWITCH statement in that routine. I agree that a good compiler could optimize the IF/THEN statements, but I would get a bit concerned at what point relationship comparisons are allowed. Two elements, as my y and x example, are not too difficult but what if someone wanted u, v, x, y, z all in one CASE relationship? That gets to be a hell of a lot of nesting. Just for the y, x example, I imagine a C translation would look something like this... Code: (Select All) if(y > 0) I don't have an editor, and bracket languages drive me a bit buggy, but I would think this is close to what would be needed to work out a template for conversion. Pete |