File: quotations.kbs

package info (click to toggle)
basic256 0.9.6.69a-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 26,304 kB
  • sloc: cpp: 7,778; yacc: 926; lex: 575; sh: 21; makefile: 7
file content (80 lines) | stat: -rw-r--r-- 3,202 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#quotations - create a database of quotations

# create a new database file or open it or create it with a few good quotes
dbfile$ = "quotations.sqlite3"
e = exists(dbfile$)
dbopen dbfile$
if (not e) then gosub createtable

gosub getlastquote
print "Database has " + lastquote + " quotes."

menu:
print "1 - view a random quote ** ";
print "2 - list all quotes ** ";
print "3 - add a quote ** ";
print "0 - quit"
input ">", choice

if choice = 1 then gosub showquote
if choice = 2 then gosub showall
if choice = 3 then gosub addquote
if choice <> 0 then goto menu

# wrap everything up
print "Good bye."
dbclose
end

showquote: ####
quote = 1 + int(rand * lastquote)
dbopenset "select author, saying from quotes where id = " + quote + ";"
while dbrow()
   print dbstring(1)
   print " - " + dbstring(0)
end while
dbcloseset
return

showall: ####
dbopenset "select id, author, saying from quotes order by id;"
while dbrow()
   print dbint(0) + " " + dbstring(2) + " (" + dbstring(1) + ")" 
end while
dbcloseset
return

addquote: ####
input "Quote>", quote$
input "Author>", author$
if quote$ = "" or author$ = "" then
   print "You must supply both a quote and an author to add."
   return
end if
lastquote = lastquote + 1
dbexecute "insert into quotes values (" + lastquote + ",'" + author$ + "','" + quote$ + "');"
print "Quote " + lastquote + " added."
return

getlastquote: ######
# find the last quote number and set the variable lastquote
lastquote = 0
dbopenset "select max(id) from quotes"
while dbrow()
   lastquote =  dbint(0)
end while
dbcloseset
return

createtable: ########
dbexecute "create table quotes (id integer primary key, author text, saying text);"
dbexecute "insert into quotes values (1,'Abraham Lincoln (1809 - 1865)','Most folks are about as happy as they make up their minds to be.');"
dbexecute "insert into quotes values (2,'George Burns (1896 - 1996)','Happiness is having a large, loving, caring, close-knit family in another city.');"
dbexecute "insert into quotes values (3,'Jean Houston','At the height of laughter, the universe is flung into a kaleidoscope of new possibilities.');"
dbexecute "insert into quotes values (4,'Doug Larson', 'Home computers are being called upon to perform many new functions, including the consumption of homework formerly eaten by the dog.');"
dbexecute "insert into quotes values (5, 'Isaac Asimov', 'I do not fear computers. I fear the lack of them.');"
dbexecute "insert into quotes values (6, 'Pierre Gallois', 'If you put tomfoolery into a computer, nothing comes out of it but tomfoolery. But this tomfoolery, having passed through a very expensive machine, is somehow ennobled and no-one dares criticize it.');"
dbexecute "insert into quotes values (7, 'Robert Orben', 'To err is human--and to blame it on a computer is even more so.');"
dbexecute "insert into quotes values (8, 'Herm Albright (1876 - 1944)', 'A positive attitude may not solve all your problems, but it will annoy enough people to make it worth the effort.');"
dbexecute "insert into quotes values (9, 'William James (1842 - 1910)', 'The greatest discovery of my generation is that a human being can alter his life by altering his attitudes of mind.');"
return