Shop OBEX P1 Docs P2 Docs Learn Events
line feed — Parallax Forums

line feed

jcleaverjcleaver Posts: 17
edited 2006-04-26 00:47 in BASIC Stamp
·simple question· when you know the answer
when you have a long program line and you want it to display better
how do you insert a line feed for display without the program thinking is a new line

seee no caps got my keyboard unstuck

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-04-25 20:40
    Try using the smallest font.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-25 20:41
    Only comma-delimited source lines can be split:

    · LOOKUP idx, [noparse][[/noparse]%000, %001, %010,······· ' this line is split
    ···············%011, %100, %101]

    Note that the trailing comma; that said, the editor is smart enough to let you have a comment on a split line.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • jcleaverjcleaver Posts: 17
    edited 2006-04-25 21:44
    here the line i am trying to break up into something readable

    main:
    IF wiper1>5120-2*delta AND wiper1< 4920 AND wiper2 < 2* delta AND wiper2 >200 THEN delta = (9*delta +(wiper2+5120-wiper1)/2)/10· ELSEIF wiper2>5120-2* delta AND wiper2<4920 AND wiper1 <2 * delta AND wiper1> 200 THEN delta = (9*delta +(wiper1+5120-wiper2)/2)/10· END IF
    does not work unless continuious line also endif gives syntax error no matter where it is
  • AdamEAdamE Posts: 11
    edited 2006-04-25 22:42
    You can use decision makers on seperate lines, that for starters ought to clean it up a bit. Eg;

    IF Condition
       Do something
    ELSEIF Condition
       Do something else
    ELSE
       Do something else
    ENDIF
    
    



    Also, if you break your formulas/equations up into variables (so instead of something like delta = (9*delta +(wiper2+5120-wiper1)/2)/10 you could first define a variable called result to equal that equation, then make delta = result. Though ofcourse you'd be trading off RAM for cleanliness.

    Im an experienced programmer with another version of BASIC (DarkBASIC Pro) but Im only just getting into using Stamp's version, so Im not sure if Stamp's version allows for functions yet, though Id imagine if it did then placing those formulas in functions would not only clean it up but also reduce the amount of code required since the formula is only written once.

    <EDIT>

    Like I said Im not too experienced with Stamp yet and I dont have the compiler/your source code on this computer but here's my attempt at shortening it up (without the use of functions as Im not sure if they're available).

    delta var byte
    
    wiper1 var byte
    wiper2 var byte
    
    result1 var byte
    result2 var byte
    
    result1 = (9*delta +(wiper2+5120-wiper1)/2)/10
    result2 = (9*delta +(wiper1+5120-wiper2)/2)/10
    
    IF wiper1 > 5120-2 * delta AND wiper1 < 4920 AND wiper2 < 2* delta AND wiper2 > 200 
       delta = result1
    ELSEIF wiper2 > 5120-2* delta AND wiper2 < 4920 AND wiper1 < 2 * delta AND wiper1 >  200
       delta = result2
    ENDIF
    
    
    



    Might want to make some of those variables constants but that looks neater alreadt [noparse];)[/noparse]

    Hope it helps,

    - Adam

    Post Edited (AdamE) : 4/25/2006 10:49:09 PM GMT
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-04-25 22:52
    IF wiper1>5120-2*delta AND wiper1< 4920 AND wiper2 < 2* delta AND wiper2 >200 THEN
    delta = (9*delta +(wiper2+5120-wiper1)/2)/10
    ELSEIF wiper2>5120-2* delta AND wiper2<4920 AND wiper1 <2 * delta AND wiper1> 200 THEN
    delta = (9*delta +(wiper1+5120-wiper2)/2)/10
    ENDIF ' <-- no space in ENDIF

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-25 23:15
    Just a note: there is no operator precedence in PBASIC so this code:

    · IF wiper1 > 5120 - 2 * delta

    evaluates as:

    · IF wiper1 > 5118 * delta

    IF that's not what you mean then you will need to use parenthesis:

    · IF wiper1 > 5120 - (2 * delta)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-25 23:24
    I may be alone in this opinion, but I think using AND with compound statements like you're doing is going to make your code really tough to troubleshoot if you have problems.· Here's how I'd code it:

    · IF wiper1 > 5120 - (2 * delta) THEN
    ··· IF wiper1 < 4920 THEN
    ····· IF wiper2 < 2 * delta THEN
    ··· ··· IF wiper2 > 200 THEN
    ····· ··· delta = (9 * delta + (wiper2 + 5120 - wiper1) / 2) / 10
    · ····· ELSE
    ··· ····· IF wiper2 > 5120 - (2 * delta) THEN
    ····· ····· IF wiper2 < 4920 THEN
    ······· ····· IF wiper1 < 2 * delta THEN
    ········· ····· IF wiper1 > 200 THEN
    ··········· ····· delta = (9 * delta + (wiper1 + 5120 - wiper2) / 2) / 10
    · ············· ENDIF
    ··· ········· ENDIF
    ····· ····· ENDIF
    ······· · ENDIF
    ····· · ENDIF
    ···· ·ENDIF
    ··· ENDIF
    · ENDIF

    The separates every term and allows you to spot errors more easily.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • jcleaverjcleaver Posts: 17
    edited 2006-04-26 00:47
    thanks all of you for your help



    tracy and jon's programs worked perfectly



    i do appreicate all your help



    have a nice dayyeah.gif
Sign In or Register to comment.