Code: Select all
dim shared as string ptr p_data = 0
dim shared as boolean endprogram
dim shared as long tinput, conc, conr ' for input start; rows/columns max
function keepstring(indata as string) as long
static as string helddata(0 to 20) ' strings to hold
static as long count ' count of items
dim as long result ' index to data
if count > 19 then ' update how many items held
count = 0
for ixi as integer = 1 to 20
if len(helddata(ixi)) > 0 then count += 1 ' something is there
next
if count > 19 then return -99 ' flag that we have no more space
end if
for ixi as integer = 1 to 20
if len(helddata(ixi)) = 0 then ' nothing is there
helddata(ixi) = indata : result = ixi ' store the data
exit for
end if
next
p_data = @helddata(0) ' update the pointer, just in case
return result
end function ' keepstring
function getstring(byref index as long) as string
dim as string result
dim as boolean remove
if p_data = 0 then return "" ' nobody home, yet
if (index > 20) or (index < -20) then return "" ' error
if index < 0 then ' flag to remove data
index = -(index) : remove = true
end if
result = p_data[index]
if len(result) = 0 then
index = -99 ' no data
else
if remove then p_data[index] = "" ' index negative == remove the data
end if
return result
end function ' getstring
function findstring(fdata as string) as long
dim as long result
if p_data = 0 then return -99 ' nobody home, yet
if len(fdata) = 0 then return -99 ' error
for ixi as integer = 1 to 20
if p_data[ixi] = fdata then
result = ixi : exit for
end if
next
return result
end function ' findstring
function keyentry() as string ' get/show key input
dim as string result, kdat
dim as integer prevrow, prevcol ' integer, long? someday will be all right
prevrow = csrlin : prevcol = pos
do
kdat = inkey ' get a key, if available
if instr(chr(27), kdat) <> 0 then
if len(result) = 0 then ' this is clear or terminate
result = chr(27)
else
result = ""
end if
locate tinput, 5, 0
print " "; space(len(result)); " "; ' clean input area
exit do ' cancel action, exit loop
end if
if len(kdat) <> 0 then ' faster test if string is empty
if instr(chr(10) & chr(13), kdat) <> 0 then ' end of entry
locate tinput, 5, 0
print " "; space(len(result)); " "; ' clean input area
exit do
else
result = result & kdat ' catch the keys
end if
end if
locate tinput, 5, 0 : print " " & result & " "; ' print clean input
sleep 8, 1
loop
locate prevrow, prevcol ' return to previous location
return left(result, 15) ' just to be a reasonable example
end function ' keyentry
sub showdata(start as long)
dim as integer prevrow, prevcol ' integer, long? someday will be all right
if p_data = 0 then return ' nobody home, yet
prevrow = csrlin : prevcol = pos
for ixi as integer = 1 to 20 ' show all data items and index
locate ((start - 1) + ixi), conc - 21, 0 : print ixi;
locate ((start - 1) + ixi), conc - 17, 0
if len(p_data[ixi]) <> 0 then
print p_data[ixi];
else
print space(conc - 17);
end if
next
locate prevrow, prevcol ' return to previous location
end sub ' showdata
' set up screen ---------------------------
screen 18 ' pick a screen
#if __FB_VERSION__ < "1.08" ' new stuff, not well tested by me yet - dnb
dim as integer shorz, svert, coffset : screeninfo shorz, svert ' pixels
#else
dim as long shorz, svert : screeninfo shorz, svert
#endif
width shorz\8, svert\16 ' my screen too big and letters too small
conc = loword(width()): conr = hiword(width) ' total columns/rows
tinput = conr - 2 ' show input at bottom of screen
coffset = 14 ' print return message from left of center of screen
print : print " screen: high = "; conc; " wide = "; conc : print
print " characters: i for input index: d for delete <ESC> to quit"
print " f to find r for retrieve"
' start of main loop ----------------------
dim as long datastart = 8 ' where to show data list
dim as boolean kpause
dim as string kkey, strdata : dim as long indexdata
locate ((datastart - 1)), conc - 23, 0
print "index data"
do
locate 1, 1, 0 : print " "; ' a 'home' for the cursor
kkey = keyentry() ' get a function choice
if kkey = chr(27) then exit do ' terminate program
kkey = lcase(kkey)
select case kkey
case "i" ' input
locate conr - 1, conc\2 - coffset, 0 : print "input";
kkey = keyentry()
if len(kkey) <> 0 then
keepstring(kkey) : kpause = true
end if
case "r" ' retrieve
locate conr - 1, conc\2 - coffset, 0 : print "find";
kkey = keyentry()
if len(kkey) <> 0 then strdata = getstring(valint(kkey))
locate conr - 1, conc\2 - coffset, 0
print " data at index "; valint(kkey); ": "; strdata; " (hit any key)";
case "d" ' delete
locate conr - 1, conc\2 - coffset, 0 : print "delete";
kkey = keyentry()
if len(kkey) <> 0 then strdata = getstring(-(valint(kkey)))
locate conr - 1, conc\2 - coffset, 0
if len(strdata) = 0 then
print kkey; " no data at"; valint(kkey); " (hit any key)";
else
print " removed: '"; strdata; "' (hit any key)";
end if
case "f" ' find index
locate conr - 1, conc\2 - coffset, 0 : print "find";
kkey = keyentry()
locate conr - 1, conc\2 - coffset, 0
if len(kkey) <> 0 then indexdata = findstring(kkey)
if indexdata > 0 then
print "'"; kkey;"' found at index "; indexdata; " (hit any key)";
else
if indexdata = -99 then
print "no data in data file to search (hit any key)";
else
print "'"; kkey; "' not found in data (hit any key)";
end if
end if
case else
sleep 20, 1
kpause = true
end select
showdata(datastart)
if not kpause then
while inkey <> "" : sleep 5,1 : wend ' clear
while inkey = "" : sleep 50,1 : wend ' sleep
while inkey <> "" : sleep 5,1 : wend ' clear ... who knows what might come next?
end if
locate conr - 1, conc\2 - coffset, 0 : print space(conc - (conc\2 - 9));
kkey = "" : kpause = false
sleep 20, 1
loop
' end of 'main' - time to exit
cls
print : print : print " program terminated" : print
' sometimes, with threads and complex input routines, input buffer for
' use by sleep doesn't get cleared correctly - this always works
while inkey <> "" : sleep 5,1 : wend ' clear
while inkey = "" : sleep 10,1 : wend ' sleep
while inkey <> "" : sleep 5,1 : wend ' clear keys ... anything could come next