PDA

View Full Version : line feed



jcleaver
04-26-2006, 03:37 AM
·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

PJ Allen
04-26-2006, 03:40 AM
Try using the smallest font.

Jon Williams
04-26-2006, 03:41 AM
Only comma-delimited source lines can be split:

· LOOKUP idx, [%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

jcleaver
04-26-2006, 04:44 AM
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

AdamE
04-26-2006, 05:42 AM
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 ;)

Hope it helps,

- Adam

Post Edited (AdamE) : 4/25/2006 10:49:09 PM GMT

Tracy Allen
04-26-2006, 05:52 AM
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 (http://www.emesystems.com)

Jon Williams
04-26-2006, 06:15 AM
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 Williams
04-26-2006, 06:24 AM
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

jcleaver
04-26-2006, 07:47 AM
thanks all of you for your help



tracy and jon's programs worked perfectly



i do appreicate all your help



have a nice dayhttp://forums.parallax.com/images/smilies/yeah.gif