Shorten this code?
FformulaA
Posts: 9
Got any ideas how to shorten this code?
Would like to use 1 SEROUT command for the strings of data. I tried storing the strings with the data variable. Sort of like this:
But all it did was put all sorts of characters on the LCD in a random fashion. Any input would be great. The code as is works, just like to save some space if I can.
GOSUB Screen_Year 'Setup Screen DO 'Goes through a loop for keys LOOP GOSUB Screen_Month 'Setup Screen DO 'Goes through a loop for keys LOOP '-----------[noparse][[/noparse]Subs(yummy)]-------------------------------- Screen_Year: SEROUT LCD, Baud, [noparse][[/noparse]LcdCls] ' Clear The LCD Display PAUSE 5 SEROUT LCD, Baud, [noparse][[/noparse]"Enter year, i.e. 5 = 2005; 99 = 2099Year:", DEC info2 ]', LcdCR] RETURN Screen_Month: SEROUT LCD, Baud, [noparse][[/noparse]LcdCls] ' Clear The LCD Display PAUSE 5 SEROUT LCD, Baud, [noparse][[/noparse]"Enter month, i.e. 1=Jan; 11=November Month:", DEC info2 ]', LcdCR] RETURN Screen_Date: SEROUT LCD, Baud, [noparse][[/noparse]LcdCls] ' Clear The LCD Display PAUSE 5 SEROUT LCD, Baud, [noparse][[/noparse]"Enter current date, Date:", DEC info2 ]', LcdCR] RETURN Screen_Day: SEROUT LCD, Baud, [noparse][[/noparse]LcdCls] ' Clear The LCD Display PAUSE 5 SEROUT LCD, Baud, [noparse][[/noparse]"Enter day of week, i.e. 1=Sun 7=Sat Day:", DEC info2 ]', LcdCR] RETURN
Would like to use 1 SEROUT command for the strings of data. I tried storing the strings with the data variable. Sort of like this:
'-----------------Variables--------------------------------------------------------- scrn_Year DATA "Enter year, i.e. 5 = 2005; 99 = 2099Year:",0 scrn_Month DATA "Enter month, i.e. 1=Jan; 11=November Month:",0 scrn_Msg VAR WORD '-------------------------------------------------------------------------------------- scrn_msg = scrn_Year GOSUB Set_Screen DO 'loop through till keys have been entered. LOOP Set_Screen: SEROUT LCD, Baud, [noparse][[/noparse]LcdCls] ' Clear The LCD Display PAUSE 5 SEROUT LCD, Baud, [noparse][[/noparse]STR scrn_msg, 13 ]
But all it did was put all sorts of characters on the LCD in a random fashion. Any input would be great. The code as is works, just like to save some space if I can.
Comments
SEROUT·LCD,·Baud,·[noparse][[/noparse]LcdCls]············'·Clear·The·LCD·Display
PAUSE·5
in several places.· That bit could be made into a subroutine of its own for a small economy.
Definitly compress the clearing, also, can you store the text portion then call it? You could do a "select case". That would elimante all the serout commands
I just dont know how to actually transfer the text, as text = "this is some text" wont work, will it?
Hopefully someone more knowlegeable than myself can clear that part up, otherwise this wont work at all.
'do your programming here
'yaddda yaddda
'Display Enter year promt
x=1
GOSUB printer
'more programming
'Display enter date
x=3
GOSUB printer
printer:
SEROUT LCD, Baud, [noparse][[/noparse]LcdCls] ' Clear The LCD Display
PAUSE 5
SELECT x
CASE 1 text = "Enter year, i.e. 5 = 2005; 99 = 2099Year:"
CASE 2 text = "Enter month, i.e. 1=Jan; 11=November Month:"
CASE 3 text = "Enter current date, Date:"
CASE 4 text = "Enter day of week, i.e. 1=Sun 7=Sat Day:"
END SELECT
SEROUT LCD, Baud, [noparse][[/noparse]text, DEC info2]', LcdCR
RETURN
Another much simpler option would be to shorten the examples, or better yet, have them enter it in a DD/MM/YYYY format.
I dont recall how off hand, at least not in PBasic, but I believe you can trim leading\trailing numbers to just select the parts you want.
Post Edited (GICU812) : 11/29/2007 2:14:25 PM GMT