Before You Post, Please Note...

-> Please Note: By Posting, you agree to submit the contents of your post to the Public Domain <- SEE: howto post to this blog

Friday, February 2, 2007

puppybasic intro ch. 07 - keyboard and data lines

green text is being edited and should not be considered  
relevant to the tutorial.
for a while, it will make up
the bulk of this section.

black text has been edited to be more accurate with
regards to puppybasic.

........................................................................
keyboard and data lines
1 of 15




an intro to puppybasic

chapter 7: keyboard and data lines







........................................................................

........................................................................
keyboard and data lines
2 of 15

let's get DATA statements out of the way, since i find them irritating,
although you'll want to know how they work when you see them in someone
else's code.

DATA statements (though as i said, i don't like them) are easy enough to
use.

anywhere in the main module of the program (don't even worry about what
that is) put the statement DATA followed by the strings or numbers you
want read, separated by commas:



........................................................................

........................................................................
keyboard and data lines
3 of 15

DATA ugh., data, statements-, that takes, me back.

READ q$: ? q$; ________________________________________________________
READ q$: ? q$; _ugh.datastatements-that takesme back.__________________
READ q$: ? q$; ________________________________________________________
READ q$: ? q$; ________________________________________________________
READ q$: ? q$;
there are better ways, but this works. if you use DATA statements, you
may find that you want to put something unique as the last string or
number so that your routine can "know" when it's done reading, but
you'll need loops and decision making (covered later) to pull it off.


........................................................................

........................................................................
keyboard and data lines
4 of 15

if you READ a number of times greater than your number of data entries,
you get an error and your program stops. to avoid this, don't read a
greater number of times than your number of entries. (heh.) along with a
unique last entry, you can reread from the beginning of your data
statements. (puppybasic looks at all of them together, from the
beginning of your program to the end, as one long data statement) by
putting an old fashioned line number (like 20) before your first data
statement, which then allows you to use the command:

RESTORE 20



........................................................................

........................................................................
keyboard and data lines
5 of 15

whenever you want to reread. you can also move to different places (in
your single virtually continuous data line) but putting line numbers
between DATA statements:

RESTORE 70: READ b$: PRINT b$ + ",";: READ b$: PRINT b$; "."

50 ________________________________________________
DATA 5,6,7,8,9 _ok,that's enough.______________________________
70 ________________________________________________
DATA ok, that's enough ________________________________________________
________________________________________________


........................................................................

........................................................................
keyboard and data lines
6 of 15

i think the most versatile way to get keyboard input is with the INKEY$
function, but it doesn't wait for input: it just says "hey! keyboard,
what's happenin'?" and unless a key has been pressed already the
keyboard just says "..." and INKEY$ returns an empty, 0-length string...
not even a space, just the nothing between two quotes, side by side: "".

there's nothing wrong with this, it's just that INKEY$ only works in a
loop, so i'll demonstrate INKEY$ after showing how loops work. in the
meantime, INPUT$(n) is similar, and not too shabby. i'll show you that
momentarily. in order to appreciate the simple beauty of INPUT$(n) you
have to see the alternatives:


........................................................................

........................................................................
keyboard and data lines
7 of 15

INPUT "", q$

you can put stuff in the quotes, and then it's like a PRINT statement,
but i prefer using PRINT to print and INPUT for input. one advantage of
separating the two is that you can put the instructions and the visible
end of the keyboard input on separate lines or different locations on
the screen. i'm really trying to set a good example here by showing
INPUT used with a comma - you could use a semicolon: INPUT ""; q$

but INPUT "please type your name - "; q$ ______________________________
will show up on the screen like this: _please type your name - ?____


........................................................................

........................................................................
keyboard and data lines
8 of 15

because as we all know the ONLY way to get information from the user is
in the form of a full sentence followed by a question mark :|

ah well. this is why using a comma is better.

of course, i don't actually recommend using the INPUT statement, ever.
LINE INPUT is used the same way you just learned (see? that wasn't in
vain) but is more reliable. i'll explain:

say for instance, you used this code:



........................................................................

........................................................................
keyboard and data lines
9 of 15

INPUT "enter your name - ", n$ _____________________________________
and say for instance, he entered: _enter your name - smith, john q.____
_____________________________________
then he would see this message: _REDO FROM START?____________________
_____________________________________
great! what? _____________________________________

it's because he typed a comma. the INPUT statement is designed so that
you can get more than one piece of data from the same prompt, separated
by commas, like this:



........................................................................

........................................................................
keyboard and data lines
10 of 15

INPUT "please enter three numbers, put commas between the first
and second, and also between the second and third, and don't forget
them, and don't put too many, or my input routine will yell at you.
thanks. ", a, b, c

assuming your plucky user gets it exactly right, the clever INPUT
statement will save an extra line of code.


Bad Design!



........................................................................

........................................................................
keyboard and data lines
11 of 15

so i never use the INPUT statement. ever. instead i use this when i want
a no fuss, two line method of getting keyboard input (there are better
ways using INKEY$, remember?)

PRINT "please enter your name. as long as your name has less than 250
characters and doesn't contain carriage returns, we shouldn't have any
problems:": ?: line input n$

all this is okay, for typing in a line of data and hitting enter. if you
have a menu on the other hand:



........................................................................

........................................................................
keyboard and data lines
12 of 15

1. do something

2. do something else

3. do something entirely different

4. exit

then the following prompt might seem reasonable:

? "please enter your selection - ";: LINE INPUT q$


........................................................................

........................................................................
keyboard and data lines
13 of 15

but i think this is better:

1. do something

2. do something else

3. do something entirely different

? "select an option (1-3) or hit [esc] to exit :)": q$=INPUT$(1)




........................................................................

........................................................................
keyboard and data lines
14 of 15

now q$ will be exactly one byte long and be a 1, or 2, or 3, or esc
(esc is ascii 27.) it might be something else, but you can check to see
if it's one of the acceptable options, and repeat until it's a key you
are looking for. yeah, i'll get to looping.

you can also change the "1" in INPUT$(1) to another number, 5 for
instance, if you want exactly 5 keys input to the program. this too, is
bad design because the person can't see what they're typing, and can't
backspace if they hit a wrong key.




........................................................................

........................................................................
keyboard and data lines
15 of 15

usually, i'll use INKEY$. in a loop, INKEY$ can act just like INPUT$(n)
if you want it to and can detect arrow and function keys as well.


-= end of chapter 7 =-








........................................................................
an intro to puppybasic (chapter 7)
this content is public domain.
........................................................................


click here to go back to the contents page

26 comments:

Anonymous said...

xanax online xanax 1mg tab - xanax for anxiety withdrawal

Anonymous said...

buy tramadol online can you buy tramadol over counter usa - generic tramadol medication

Anonymous said...

buy tramadol online tramadol for dogs onset of action - tramadol 100mg seizure

Anonymous said...

buy tramadol online buy tramadol online in europe - tramadol hcl 50 mg mylan

Anonymous said...

xanax online long does generic xanax last - normal dosage xanax anxiety

Anonymous said...

buy tramadol online tramadol normon 50 mg para que sirve - buy tramadol for dogs usa

Anonymous said...

tramadol online no prescription tramadol withdrawal what to do - buy tramadol hydrochloride online

Anonymous said...

carisoprodol 350 mg carisoprodol class of drug - carisoprodol 5 panel drug test

Anonymous said...

buy tramadol tramadol quick release - tramadol online apotheke

Anonymous said...

cialis drug buy cialis online american express - buy cialis online in malaysia

Anonymous said...

cialis pills buy cialis online us no prescription - buy cialis online overnight shipping

Anonymous said...

buy cialis generic order cialis us - cialis coupon voucher

Anonymous said...

cialis online usa is it safe to buy cialis online usa - cialis 80 mg price

Anonymous said...

cialis online cialis online miglior prezzo - cialis best price

Anonymous said...

cialis online cialisonline.it - order generic cialis online

Anonymous said...

tramadol 50 tramadol 50mg good high - tramadol 50mg bula

Anonymous said...

buy tramadol 100mg tramadol vs percocet - tramadol hydrochloride for dogs side effects

Anonymous said...

order tramadol online mastercard tramadol online - order tramadol with money order

Anonymous said...

http://blog.dawn.com/dblog/buy/#34852 tramadol hcl hcl - order tramadol free shipping

Anonymous said...

http://blog.dawn.com/dblog/buy/#about-us buy tramadol online europe - tramadol 50mg generic

Anonymous said...

tramadol online no prescription buy tramadol online in usa - tramadol hcl 50mg tablet amnea

Anonymous said...

buy tramadol tramadol 50mg generic - ordering tramadol online legal

Anonymous said...

buy tramadol illegal order tramadol online - tramadol 50mg wiki

Anonymous said...

buy tramadol online tramadol high mg - zydol tramadol overdose

Anonymous said...

xanax medication upjohn generic xanax - xanax white pill

Anonymous said...

xanax 0.5mg effects xanax birth control pills - xanax dosage how long does it last