Shop OBEX P1 Docs P2 Docs Learn Events
Want to convert PBASIC IF THEN with AND statements into SX/B. Is my SX/B code c — Parallax Forums

Want to convert PBASIC IF THEN with AND statements into SX/B. Is my SX/B code c

T&E EngineerT&E Engineer Posts: 1,396
edited 2007-04-09 19:20 in General Discussion
I have some PBASIC code that I want to convert in function to SX/B code. Is my SX/B code correct or is there a better way to do this?

'PBASIC code (working)

TimeMessages:
· IF ((hrs >= $00) AND (hrs < $12)) THEN
· 'Coding here "Good Morning".....
· ELSEIF ((hrs >=$12) AND (hrs < $18)) THEN
· 'Coding here "Good Afternoon"....
· ELSEIF ((hrs >=$18) AND (hrs < $24)) THEN
· 'Coding here "Good Evening".....
· ENDIF
·RETURN


' SX/B equivalent?? - Does this look right?

TimeMessages:
· IF TimeDate(Hrs) >= $00 THEN
··· IF TimeDate(Hrs) < $12 THEN
······'Coding here "Good Morning".....
··· ENDIF
· ENDIF
· IF TimeDate(Hrs) >= $12 THEN
··· IF TimeDate(Hrs) < $18 THEN
······ 'Coding here·"Good Afternoon".....
··· ENDIF
· ENDIF
· IF TimeDate(Hrs) >= $18 THEN
··· IF TimeDate(Hrs) < $24 THEN
······'Coding here "Good Evening"....
··· ENDIF
· ENDIF
RETURN

Comments

  • JonnyMacJonnyMac Posts: 9,214
    edited 2007-04-09 14:09
    Even your original code is working harder than it has to; here's how to do it easily in SX/B:

    IF hrs < $12 THEN
      ' good morning
    ELSEIF hrs < $18 THEN
      ' good afternoon
    ELSE
      ' good evening
    ENDIF
    
  • T&amp;E EngineerT&amp;E Engineer Posts: 1,396
    edited 2007-04-09 18:35
    Thank you JonnyMac. Initial testing indicates this is working correctly.
  • JonnyMacJonnyMac Posts: 9,214
    edited 2007-04-09 19:16
    Listen, Tim, I wouldn't have posted code that doesn't work.... That you're not always able to understand or incorporate code that others share with you doesn't me that the contributor is at fault.
  • T&amp;E EngineerT&amp;E Engineer Posts: 1,396
    edited 2007-04-09 19:20
    Oh. Im sorry. I did not mean to sound offensive. Your code is always in great form. As a test engineer, I guess it is my thinking process out loud. I was not putting any blame on you at all. I will just have to test out my implementation of your code in my program in more detail tonight that's all. Thanks again for your help!
Sign In or Register to comment.