Shop OBEX P1 Docs P2 Docs Learn Events
IF...THEN question? — Parallax Forums

IF...THEN question?

MichelBMichelB Posts: 154
edited 2009-09-29 07:12 in BASIC Stamp
Hi all, I've a little problem with the attached code, when I enter a wrong number DEBUG tell me that the number is wrong but the program continues. I'm not sure that my IF...THEN is correct, I don't find an identical example in BASIC Stamp manual. An other problem, but it concerns Tracy Allen, when I enter a negative N and a positive D I obtain a positive result. Thank you in advance for your help. MichelB

Note: attached file has been deleted.

Post Edited (MichelB) : 8/4/2009 3:45:16 PM GMT

Comments

  • dev/nulldev/null Posts: 381
    edited 2009-08-03 16:41
    DO 
    
    numerator:
    DEBUG CLS, "Enter Numerator -32767 < N < +32767:", CR
    DEBUGIN SDEC N
    IF (N < -32767) OR (N > 32767) THEN
      DEBUG "N must be between -32767 and +32767"
      PAUSE 1000
      GOTO numerator
    ENDIF
    
    denominator:
    DEBUG CLS, "Enter Denominator -32767 < D < +32767:", CR
    DEBUGIN SDEC D
    IF (D < -32767) OR (D > 32767) THEN
      DEBUG "D must be between -32767 and +32767"
      PAUSE 1000
      GOTO denominator
    ENDIF
    
    etc...
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • MichelBMichelB Posts: 154
    edited 2009-08-04 07:30
    Thank you dev/null, but it does not work. Even numerator is in the range of -32767 to +32767 program returns to "Enter Numerator...".
    Please try with the attached code.

    P.S.: Program runs well when "numerator:",·"denominator:" are removed and when OR between IF...THEN are replaced by AND, except if N is out of range, try with the attached code Rev.

    Post Edited (MichelB) : 8/4/2009 7:58:00 AM GMT
  • dev/nulldev/null Posts: 381
    edited 2009-08-04 13:27
    I was a bit quick, didn't look over your code. Your problem is that BS2 only accepts 16-bit variables. So the maximum values that you can input from DEBUGIN using the SDEC operator is -32767 to 32767!
    For the DEC operator the values are 0 to 65535.

    Any value outside this interval will automatically be truncated to a value inside the interval.

    If you want to have this type of error checking, you have to do some fancy coding using DEBUGIN with strings. I'm not sure you want to go that route?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • MichelBMichelB Posts: 154
    edited 2009-08-04 14:28
    Yes I know what you write and this program from Tracy Allen's app-notes can divide numbers in the range of -32767 to +32767. What I want exactly is a line of code (IF...THEN) telling me that the number entered is out of range and asking to enter an other number and this for the numerator and denominator. I've had a similar question some months ago and Jessica from Parallax found solution but I forgotten the related file, I've more than 200 bs2 files.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-09-29 06:01
    Just a suggestion. You can do a search for all the posts you have done and you may find the one that worked before. I have actually found posts from over 4 years ago that I had done.
  • MichelBMichelB Posts: 154
    edited 2009-09-29 07:12
    OK, thank you.
Sign In or Register to comment.