Ask Your Question
0

Select Case where Case has more than one test

asked 2017-12-10 04:08:02 +0200

digifoss gravatar image

updated 2017-12-10 16:32:29 +0200

erAck gravatar image

Using LO 5.4 for Win_64

I am unable to return TRUE on either cae in the following Select Case... To find 10% I need to know that CASE is both Equal to or greater than progCount AND less-than ( progCount * 2) and so on.....

counter = 386

progCount = (counter / 10)

for i = 1 to counter step 8

Select Case i       
        case >=(progCount) & < (progCount * 2)
        msgBox "10%"
        case  >=(progCount * 2) & < (progCount * 3)
        msgBox "20%"
        REM ...

    End Select

next i

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2017-12-10 04:48:46 +0200

librebel gravatar image

Hello @digifoss,

i don't think the expression after "case" can start with an operator. Please try with "To" instead:

Select Case i       
    case (progCount) To (progCount * 2)
        msgBox "10%"
    case (progCount * 2) To (progCount * 3)
        msgBox "20%"
    REM ...
End Select

HTH, lib

edit flag offensive delete link more

Comments

Jim K gravatar imageJim K ( 2017-12-10 07:25:05 +0200 )edit
1

answered 2017-12-10 11:21:48 +0200

Lupp gravatar image

updated 2017-12-10 12:23:05 +0200

Editing

The operator & is not a logical conjunction. It denotes for concatenation of strings. The Select Case construct uses the comma in place of the logical disjunction (OR). There is no substitute for AND as far as I know. My suggestion:

Select Case Int(i / progCount)  
  Case 1 : msgBox "10%"
  Case 2 : msgBox "20%"
End Select

Credits to @librebel , of course.
(And the colons were missing. The above linked wiki page seems to be incorrect. Tell me, please if it's otherwise. See also my comment.)

edit flag offensive delete link more

Comments

I see. The example given in the above linked wiki page is working.
I now wonder if this is just a case of permissive behaviour of the interpreter or actually specified BASIC syntax.
It's a mess if we are subject to the modern ways where you have to learn from examples instead of mandatory specifications. Who selects the examples and by what means does he (f/m) make sure they are correct?
See also!

Lupp gravatar imageLupp ( 2017-12-10 11:34:07 +0200 )edit

The colon is a usual Basic syntax to allow two statements on one line. If put on different lines, no colons required.

Mike Kaganski gravatar imageMike Kaganski ( 2017-12-10 12:05:53 +0200 )edit

Thanks for both suggestions guys. I saw Jim K answer last night and that worked great, so I changed it using TO and removed the operators.

digifoss gravatar imagedigifoss ( 2017-12-10 18:26:37 +0200 )edit

@Mike Kaganski: I know about the colon as statement delimiter. However the BASIC guide I linked to (anchor: "See also!") puts it as if the colon also separates the Case part from the statement part of a case. The missing clarity in such things was what I critisized. An additional empty statement created by a spare colon should not be a problem..

Lupp gravatar imageLupp ( 2017-12-10 20:29:31 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-12-10 04:08:02 +0200

Seen: 45 times

Last updated: Dec 10 '17