Address Book - Using Database (Sample Programs)

by Jim ⌂ @, Russell, KY, Thursday, February 17, 2011, 20:45 (2829 days ago)

Gib had asked me about an address book application. I took the program from the Example folder to maintain quotations and changed it into this very simple address book.

Jim

#addressfile - create a database of names and addresses
# 2011-02-17 j.m.reneau

# open database file - if it is new then create the table to store addresses
dbfile$ = "addressfile.sqlite3"
e = exists(dbfile$)
dbopen dbfile$
if (not e) then
dbexecute "CREATE TABLE address (name TEXT, address TEXT, city TEXT, state TEXT, zip TEXT, phone TEXT);"
end if

menu:
print "1 - find an address"
print "2 - list all"
print "3 - add an address"
print "0 - quit " ;
input ">", choice

if choice = 1 then gosub findaddress
if choice = 2 then gosub showall
if choice = 3 then gosub addaddress
if choice <> 0 then goto menu

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

findaddress: ####
input "enter part of name>", name$
dbopenset "SELECT name, address, city, state, zip, phone FROM address WHERE name LIKE '%" + name$ + "%';"
while dbrow()
gosub showsingle
end while
dbcloseset
return

showall: ####
dbopenset "SELECT name, address, city, state, zip, phone FROM address ORDER BY name;"
while dbrow()
gosub showsingle
end while
dbcloseset
return

showsingle: ####
print dbstring(0) + " " + dbstring(1) + " " + dbstring(2) + " " + dbstring(3) + " " + dbstring(4) + " " + dbstring(5)
return

addaddress: ####
input "name>", name$
if name$ = "" then
print "add aborted"
return
end if
input "address>", address$
input "city>", city$
input "state>", state$
input "zip>", zip$
input "phone>", phone$
dbexecute "INSERT INTO address (name, address, city, state, zip, phone) VALUES ('" + name$ + "','" + address$ + "','" + city$ + "','" + state$ + "','" + zip$ + "','" + phone$ + "');"
print "Address added."
return


Complete thread:

 RSS Feed of thread

powered by my little forum