![]() |
Using _Andalso with Select Case - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +--- Thread: Using _Andalso with Select Case (/showthread.php?tid=3701) |
Using _Andalso with Select Case - Dimster - 05-21-2025 I have used the logical operator _Andalso in IF...Then statements however I'm not sure if this logical operator works in Select Case. Is this because Select Case: Case is .. will only accept =,<>,<,> the logical operators like And, Or, Xor, _Andalso do not work with Case is..? RE: Using _Andalso with Select Case - hsiangch_ong - 05-21-2025 select case... end select wasn't designed for the application you described. what is the fear of using ordinary if... then... else... end if block? select case was created in a time. where it looked like basic would never offer short-circuit evaluation. while it's offered in qb64pe. it has to be only in if... then... else... end if block. otherwise it would be confusing. i don't think other programming languages are different about it. although i've seen c code that is simply mind-boggling. could do something like this: Code: (Select All) a = 4 RE: Using _Andalso with Select Case - TempodiBasic - 05-22-2025 Never used _ANDALSO but I find it useful when I must test 2 conditions and the second can be false and it triggers a runtime error like for example out of range, so before the existence of _AndAlso I must write a first IF for the field of values good so that the second condition in the second IF doesn't trigger a runtime error. Code: (Select All)
But as Wiki explains it is useful for avoiding so many actions required in the following AND conditions when the first is false and the final result of conditions is false.Select case let you set the values or the range of values to perform some actions. In this kind of decisions about one variable: the values that activate the same action have been typed in the same CASE as a range or a list of values/conditions Select Case wiki page so you can put the _andalso conditions into the same CASE block without using _andalso keyword. RE: Using _Andalso with Select Case - Dimster - 05-22-2025 Thanks very much for your suggestions on a workaround for Case is > A AndAlso A < C . I find I prefer a Select Case than an IF..THEN decision structure. I was also thinking I may be able to create a workaround if there was a Select Case True, but doesn't appear that that is in the Select Case arsenals. The ability to short circuit a decision with multiple conditions has been a great addition to the Logical Operators and I use it a lot with IF...THEN. It just occurred to me that I haven't tried more than one other condition, I wonder how _Andalso works with many multiple conditions? For example: If A>B _Andalso B>C _Andalso C>D _Andalso D=>A THEN Print "This will never work" Thanks again for your suggestions and comments. |