Here is a simple demo application for our keyed lookup library in development. It opens a window with keys on the left, and a text editor on the right. You can add new keys and edit the values for those keys by changing text on the right. The values are saved to the file dictionary.dat.
We will enhance this code for a couple more blog entries before we move on to some other project. :-)
Enjoy!
nomainwin
WindowWidth = 555
WindowHeight = 438
dim keys$(1000)
dim info$(10, 10)
global dictionary$, keyCount, lastKey$
call readDictionary
texteditor #main.value, 175, 7, 360, 365
listbox #main.keys, keys$(), [keySelected], 5, 7, 160, 365
menu #main, "Key", "New", [newKey], "Delete", [deleteKey]
menu #main, "Edit"
open "Dictionary inspector" for window as #main
#main "trapclose [quit]"
#main.keys "singleclickselect"
#main.value "!autoresize";
call loadKeys
[main.inputLoop] 'wait here for input event
wait
[newKey] 'ask the user for a new key
call saveValue
prompt "Enter a name for the key."; newKey$
if newKey$ <> "" then
call setValueByName newKey$, ""
call loadKeys
#main.keys "select "; newKey$
#main.value "!cls";
#main.value "!setfocus";
call writeDictionary
lastKey$ = newKey$
end if
wait
[deleteKey] 'left for later
notice "Delete not implemented yet."
wait
[keySelected] 'a key in the list was selected
call saveValue
#main.keys "selection? selectedKey$"
selectedValue$ = getValue$(selectedKey$)
#main.value "!contents selectedValue$";
lastKey$ = selectedKey$
wait
[quit] 'End the program
call saveValue
close #main
end
sub saveValue 'if the value is changed, save it
if lastKey$ <> "" then
#main.value "!modified? modified$";
if modified$ = "true" then
#main.value "!contents? saveThisValue$";
call setValueByName lastKey$, saveThisValue$
call collectGarbage
call writeDictionary
end if
end if
end sub
function getKeys$(delimiter$)
global keyCount
pointer = 1
while pointer > 0
'get the next key
pointer = instr(dictionary$, "~key~", pointer)
if pointer then
keyPointer = pointer + 5
pointer = instr(dictionary$, "~value~", pointer)
key$ = mid$(dictionary$, keyPointer, pointer - keyPointer)
if instr(keyList$, "~key~" + key$) = 0 then
getKeys$ = getKeys$ + key$ + delimiter$
keyList$ = keyList$ + "~key~" + key$
keyCount = keyCount + 1
end if
end if
wend
end function
sub writeDictionary
open "dictionary.dat" for output as #writeDict
print #writeDict, dictionary$
close #writeDict
end sub
sub readDictionary
if fileExists(DefaultDir$, "dictionary.dat") then
open "dictionary.dat" for input as #readDict
length = lof(#readDict)
dictionary$ = input$(#readDict, length)
close #readDict
end if
end sub
sub collectGarbage
pointer = 1
while pointer > 0
'get the next key
pointer = instr(dictionary$, "~key~", pointer)
if pointer then
keyPointer = pointer + 5
pointer = instr(dictionary$, "~value~", pointer)
key$ = mid$(dictionary$, keyPointer, pointer - keyPointer)
if instr(keyList$, key$) = 0 then
value$ = getValue$(key$)
newDictionary$ = "~key~" + key$ + "~value~" + value$ + newDictionary$
keyList$ = keyList$ + key$
end if
end if
wend
dictionary$ = newDictionary$
end sub
sub setValueByName key$, value$
dictionary$ = "~key~"+key$+"~value~"+value$+dictionary$
end sub
function getValue$(key$)
getValue$ = chr$(0)
keyPosition = instr(dictionary$, "~key~"+key$)
if keyPosition > 0 then
keyPosition = keyPosition + 5 'skip over key tag
valuePosition = instr(dictionary$, "~value~", keyPosition)
if valuePosition > 0 then
valuePosition = valuePosition + 7 'skip over value tag
endPosition = instr(dictionary$, "~key~", valuePosition)
if endPosition > 0 then
getValue$ = mid$(dictionary$, valuePosition, endPosition - valuePosition)
else
getValue$ = mid$(dictionary$, valuePosition)
end if
end if
end if
end function
sub loadKeys
keyList$ = getKeys$("~")
redim keys$(keyCount)
for item = 1 to keyCount
keys$(item-1) = word$(keyList$, item, "~")
next item
#main.keys "reload"
end sub
function fileExists(path$, filename$) ' Does file exist?
files path$, filename$, info$(
fileExists = val(info$(0, 0)) > 0
end function
Showing posts with label demo. Show all posts
Showing posts with label demo. Show all posts
Wednesday, July 20, 2016
Friday, May 04, 2007
Demo of Run BASIC at Smalltalk Solutions
Wednesday evening I had the priviledge of organizing the Seaside BOF (birds of a feather) session at Smalltalk Solutions. This meant that I was the one up at the microphone (which I pushed aside since the room wasn't big) for most of an hour and a half. It was fun and I didn't feel put on the spot since this was more of a round table than anything. I only had to try and direct the conversation some.
Here is James Robertson's blog entry with a photo of me presenting.
http://www.cincomsmalltalk.com/blog/blogView?entry=3355631481
I'm very small in the frame, but yeah that's me all right. You can make out the Run BASIC web page up on the screen if you look carefully.
The demo was a little bit scary since I was modifying the Run BASIC code almost right up to the last second before the meeting. Scott and I were spending most of our free time at the conference working on some simple CSS integration. I'm hoping to put a screencast up to show how it all works.
Here is James Robertson's blog entry with a photo of me presenting.
http://www.cincomsmalltalk.com/blog/blogView?entry=3355631481
I'm very small in the frame, but yeah that's me all right. You can make out the Run BASIC web page up on the screen if you look carefully.
The demo was a little bit scary since I was modifying the Run BASIC code almost right up to the last second before the meeting. Scott and I were spending most of our free time at the conference working on some simple CSS integration. I'm hoping to put a screencast up to show how it all works.
Labels:
basic,
css,
demo,
liberty basic,
qbasic,
run basic,
seaside,
smalltalk,
web applications
Subscribe to:
Posts (Atom)