Complex argument (well for me it is!)

10100011

New Member
Hi guys and girls :D

Right, im trying to write some code to read the analouge voltage on ADC 0 and ADC 1, but i want it to see if the value is between certain ranges i.e.

if b0 =>242 AND <=255
As the first part of the argument, but also

if b1 =>242 AND <=255
But I want it in the same argument like this:

if b0 =>242 AND <=255 AND if b1 =>242 AND <=255 then ....
I've tried what was in the last quote, but i think it was confused :confused: Any help on this would be great.

Thank you!
 

westaust55

Moderator
Try this:

Code:
if b0 >= 242 AND b0 <=255 THEN
  IF b1 >= 242 AND b1 <= 255 Then
    ;do what you wish to here
  ENDIF
ENDIF
Keep in mind that a byte variable cannot be greater than 255 so, unless you might later reduce the upper limit, then the second part of these statements (the AND bx <= 255) could be deleted.
 

Technical

Technical Support
Staff member
if b0 >= 242 and b0 <=255 then
if b1 >=242 and b1 <=255 then
...your code here
end if
end if
 

10100011

New Member
my gosh those replies were quick!! :D Thanks for helping!

Are both those codes the same (except for layout) ?

Im assuming that leaving the "then.." part empty somehow tells the chip to take into account another argument before doing anything?
 

Jeremy Leach

Senior Member
Just to be a smart arse ...

What you're really saying is: If b0>=242 and b1 >= 242 then <do whatever>
But b0 is the least significant byte of the word variable w0, and b1 is the most significant byte of w0

If b0 is 242 and b1 is 242 then w0 = (242 * 256) + 242 = 62194

So I think the easiest way of writing your code is actually just ...

Code:
If w0 >= 62194 Then
    Do whatever
End if
 

Pekari

Senior Member
No, no, no!

If b0=0 and b1=243 then w0=62208?

if b0=0...255 and b1<242 then Do whatever!
 
Last edited:

hippy

Ex-Staff (retired)
@ 10100011 : I'd go with westaust55 in post #2.

And, as noted, if you are using <= 255 that can be deleted, which would also allow -

Code:
If b0 >= 242 and b1 >= 242 Then
  [i]Do whatever you need to here[/i]
End If
 

hippy

Ex-Staff (retired)
Jeremy : If we didn't have smart ideas which looked good on paper we wouldn't have bugs and we'd be bored half the time ! It's always amazing how quickly someone can spot the flaw in someone's suggestion, and equally amazing when no one does.
 

10100011

New Member
:eek:Would you mind if I just stick with the first answers?? :D

Do i need to do anything special if i want to repeat that argument, say, 9 more times? :confused:

BTW, thanks for everyone help, its great to have a forum that is not only quick to respond but quick to respond with actual answers :D
 

10100011

New Member
Sorry to be a pain :eek: But its not working :confused: I keep getting this error with the "AND" parts of the argument:



I've tried removing the "=" and putting in extra spaces and all sorts, but to no avail :confused: Am I forgetting something??
 

hippy

Ex-Staff (retired)
A slight aside ... Why do I get a completely different error message pop-up style ? Are you on an older version of the Programming Editor ?

I must say I don't particularly like the new visual style of error message though its content is much more informative.
 

Attachments

Top