Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:58 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MMBasic valid criteria

Author Message
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 986
Posted: 05:54am 22 Dec 2022
Copy link to clipboard 
Print this post

Is this type of expression valid in MMBasic:
IF 0 <= Variable <= 10 Then

?????????????
OA47
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 06:07am 22 Dec 2022
Copy link to clipboard 
Print this post

No
If you try you will get caught up in comparing the result of a comparison with the other value/expression.
If (0 <= variable) and (variable <= 10)
I am not sure if the brackets are required. I did experiment with that some time ago. Too many electrons flowed under the bridge since then...

You could do a function if there are a few to do,

Jim
VK7JH
MMedit
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 986
Posted: 06:31am 22 Dec 2022
Copy link to clipboard 
Print this post

Thanks Jim. The program was accepting the code (I am not sure which variation of Basic I got it from) but I was getting unpredictable outcomes.
Merry Christmas
OA47
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 09:02am 22 Dec 2022
Copy link to clipboard 
Print this post

select/case might be a fit for you - it has a close enough syntax to what you give above:

Select Case x
  Case 0 To 10
     ...
End Select

bit long-winded if you are doing just a single comparison tho'

also, consider Constrain(), that might fit what you are doing.

h
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 442
Posted: 03:16pm 22 Dec 2022
Copy link to clipboard 
Print this post

  OA47 said  Is this type of expression valid in MMBasic:
IF 0 <= Variable <= 10 Then

?????????????
OA47


In many BASICs, the first part (0 <= Variable) will return a -1 if variable >=0 and a 0 if variable <0.
Then it will compare that result with 10.

Since both 0 and -1 are <=10 the branch will always be taken
Edited 2022-12-23 01:20 by toml_12953
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025