Post by xxgeek on Jul 13, 2021 1:45:38 GMT
In the code below there is a list box, and a texteditor to add Listings, and edit the text.
It works great, but I want to be able to click on each radio button for differing topics, but reuse the Listbox, and texteditor.
As is the List, and the text are saved to dictionary.dat.
For each radio button click, I'd like to have the List, and text saved to the corresponding radio buttons Title. Programs save to programs.dat, examples saved to examples.dat. etc
The way the code is right now, it doesn't work. I'm missing something.
I'm trying to make a help app for Just Basic to add to PO.
Most of the code was written by cundo, Carl Gundel, and some from enzo. I get back to it every so often to see what I can come up with and I believe I'm getting close, but no cigar yet. Anyone with enough spare time to read the code and see where it's gone wrong can have a free copy when/if it ever gets completed. So can everyone else though
It works great, but I want to be able to click on each radio button for differing topics, but reuse the Listbox, and texteditor.
As is the List, and the text are saved to dictionary.dat.
For each radio button click, I'd like to have the List, and text saved to the corresponding radio buttons Title. Programs save to programs.dat, examples saved to examples.dat. etc
The way the code is right now, it doesn't work. I'm missing something.
I'm trying to make a help app for Just Basic to add to PO.
Most of the code was written by cundo, Carl Gundel, and some from enzo. I get back to it every so often to see what I can come up with and I believe I'm getting close, but no cigar yet. Anyone with enough spare time to read the code and see where it's gone wrong can have a free copy when/if it ever gets completed. So can everyone else though
' another help file viewer
' (C) 2020 by cundo
' find this code and discussion at justbasiccom.proboards.com
' version: 1002
' fast start coding helper v102
' by cundo (c) 2020
' find this code and discussion at justbasiccom.proboards.com
'cundo's jbsearch code
JBpath$ = "c:\Program Files (x86)\Just Basic v2.0\"
if VAL(Version$)<2 then
notice "Just BASIC 2.0 required"
end
end if
helpFilePath$ = JBpath$;"\jb2help\JustBASIC_2_web"
helpFileMenu$ = "amber_menu.htm"
if fileExists(helpFilePath$, helpFileMenu$)=0 then
notice "Program Terminated";chr$(13);_
"Couldn't find the help files"
end
end if
'Carl Gundel's Dictionary code
global dictionary$, keyCount, lastKey$, categorie$, helpFilePath$
categorie$ = "dictionary.dat"
call readDictionary
''fastcode code by cundo
dim ar$(500), searchList$(500)
dim br$(19)
br$(1)= "window"
br$(2)= "window_nf"
br$(3)= "window_popup"
br$(4)= "dialog"
br$(5)= "dialog_modal"
br$(6)= "dialog_nf"
br$(7)= "dialog_popup"
br$(8)= "graphics"
br$(9)= "graphics_nsb"
br$(10)= "graphics_nsb_nf"
br$(11)= "graphics_nf"
br$(12)= "graphics_fs"
nomainwin
WindowWidth = 1000
WindowHeight = 700
UpperLeftX= int((DisplayWidth-WindowWidth)/2)
UpperLeftY= int((DisplayHeight-WindowHeight)/2)
open helpFilePath$;"\";helpFileMenu$ for input as #1
txt$ = input$(#1, lof(#1))
close #1
' do a lower case version of the html file
' to avoid discrepances or whatever.
lowerTxt$= lower$(txt$)
while 1
scan
startAt = c+1
a = instr(lowerTxt$, "href",startAt)
b = instr(lowerTxt$, ">",a+1)
c = instr(lowerTxt$, "</a>",b+1)
if a=0 or b=0 or c= 0 then exit while
hrefA= instr(lowerTxt$,chr$(34),a+1)
hrefB= instr(lowerTxt$,chr$(34),hrefA+1)
idx = idx +1
ar$(idx)= trim$(mid$(txt$,b+1,c-b-1));chr$(0);_
trim$(mid$(txt$,hrefA+1,hrefB-hrefA-1))
wend
'dictionary code by Carl Gundel
texteditor #main.value, 175, 340, 800, 240
listbox #main.keys, keys$(), [keySelected], 5, 340, 160, 240
'menu #main, "New", Listing, [newKey]
menu #main, "Edit"
'jbsearch code by cundo
listbox #main.listbox1, ar$(, lbDoubleClick, 420, 35, 170, 295
textbox #main.tb, 600, 35, 170, 25
listbox #main.listbox2, searchList$(, lbDoubleClick, 600, 65, 170, 265
statictext #main.contents, "Just Basic Help", 460, 10, 110, 25
button #main.search, "&Search Help Files", buttonClick, UL, 610, 5, 120, 25
button #main.help, "?", buttonClick, UL, 735, 5, 26, 25
button #main.newlisting, "New Listing", [newKey], UL, 20, 310, 85, 25
statictext #main.paste, "Select New Listing - Paste Text Above - Or Edit Text", 450, 580, 340, 25
'xxgeek's code
progs$ = "Programs"
comms$ = "Commands"
exams$ = "Examples"
snipps$ = "Snippets"
selfhelp$ = "Self-Help"
'xxgeeks code
groupbox #main.chosenCategory, "Choose a Category", 10, 590, 400, 45
radiobutton #main.programs, progs$, [progs], resetHandler, 10, 610, 80, 20
radiobutton #main.commands, comms$, [comms], resetHandler, 90, 610, 85, 20
radiobutton #main.examples, exams$, [exams], resetHandler, 180, 610, 80, 20
radiobutton #main.snippets, snipps$, [snipps], resetHandler, 260, 610, 70, 20
radiobutton #main.selfhelp, selfhelp$, [selfhelp], resetHandler, 335, 610, 80, 20
'fastcode by cundo
texteditor #main.ed, 8, 120, 400, 170
statictext #main.st2, "Select Type of >", 5, 60, 95, 20
statictext #main.st1, "< Name && Handle >", 155, 18, 128, 20
textbox #main.txt1, 300, 16, 100, 25
textbox #main.txt2, 30, 16, 100, 25
button #main.button1, "Generate Window Code", dummy, ul, 130, 295, 150, 25
combobox #main.combo, br$(, dummy, 110, 55, 222, 20
checkbox #main.r1, "Use Branches instead of Subs", dummy, dummy, 8, 90, 222, 20
'menu by enzo
menu #main, "Math", "rnd(", [onMathRnd], "val(", [onMathVal], "not(", [onMathNot], "sqr(", [onMathSqr]
menu #main, "Strings$", "string$ = input$", [onStringsStringInput], |, "Globalize", [onStringsGlobalize], |, "Left$( Right$( Word$(", [onStringLeft], "TRIM$( MID$( CHR$(", [onStringstmc]
menu #main, "Functions", "Function(", [onFunctionsFunction], "Function$(", [onFunctionsFunctionstring]
menu #main, "Loops", "for next", [onLoopsForNext], "if then var = var + 1 var = x", [onLoopsIfThe], "while wend", [onLoopsWhileWend], "do while", [notice], |, "if then else", [onLoopsIfThenElse], |, "if then end if", [onLoopsIfThenEndIf]
menu #main, "INPUT DATA$", "Var", [onINPUTDATAVar], "String$", [onINPUTDATAString], "array$(", [onINPUTDATAArray], "array(", [onINPUTDATAArray]
menu #main, "File Operations", "open for input", [onFileOperationsOpenForInput], |, "Output", [onFileOperationsOutput], "Append", [onFileOperationsAppend]
menu #main, "select case", "select case$", [fixMe] ' <-- this menu has no items!
'jbsearch code - cundo
open "Just Basic Help Lab" for window as #main
#main "trapclose quit"
#main.listbox1 "singleclickselect"
#main.listbox2 "singleclickselect"
#main "font arial 10 "
#main.txt1 "#main"
#main.txt2 "untiltled"
#main.r1 "set"
#main.ed "!font tahoma 8"
#main.combo "selectindex 1"
#main.keys "singleclickselect"
#main.value "!autoresize";
call loadKeys ' dictionary code
[main.inputLoop] 'wait here for input event
wait
'Dictionary by Carl Gundel
[newKey] 'ask the user for a new key
call saveValue
prompt "Enter a Name for the New Listing"; newKey$
if newKey$ <> "" then
call setValueByName newKey$, ""
call loadKeys
#main.keys "select "; newKey$
#main.value "!cls";
#main.value "!setfocus";
call collectGarbage
call writeDictionary
lastKey$ = newKey$
end if
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
instructions$ = "Select an item from the ";_
"list to view the article on your web browser."
sub quit fast$
call saveValue
'run "taskkill /IM htmlviewer.exe" - xxgeeks personal version closes opened htm help viewers on exit
close #fast$ : end
end sub
'xxgeek's code
[progs]
call saveValue
categorie$ = progs$
#main.keys "reload"
call readDictionary
call loadKeys
wait
[comms]
call saveValue
categorie$ = comms$
#main.keys "reload"
call readDictionary
call loadKeys
wait
[exams]
call saveValue
categorie$ = exams$
#main.keys "reload"
call readDictionary
call loadKeys
wait
[snipps]
categorie$ = snipps$
#main.keys "reload"
call readDictionary
call loadKeys
wait
[selfhelp]
call saveValue
categorie$ = selfhelp$
#main.keys "reload"
call readDictionary
call loadKeys
wait
'jbsearch code - cundo
sub buttonClick h2$
select case word$(h2$,2,".")
case "contents"
case "help"
notice "Help";CHR$(13);_
"From the Contents list, single click an";_
" item and the web browser will display the topic.";_
CHR$(13);CHR$(13);_
"From the Search list (empty at start), write";_
" a word, and press the Enter key or press the Go button, to search.";_
CHR$(13);CHR$(13);_
"How to append this program to the Just BASIC Run menu for easy access.";_
CHR$(13);_
"1) Tokenize this program's code: Run menu > Make *.tkn File.";_
" Use any name for the file,";_
" remember where this file is, and how it is named.";_
CHR$(13);_
"2) Select the menu Setup > External Programs";_
CHR$(13);_
"3) Click on the New button, choose a name of your liking to create a new item.";_
" This is the name that will appear under the JB's Run menu. So choose a descriptive name.";_
CHR$(13);_
"4) Select the created item.";CHR$(13);_
"5) Click on the Browse menu, and look for your previously created tkn file on step 1.";_
CHR$(13);_
"6) Just BASIC will tell you should restart the Editor."
case "search"
#main.tb "!setfocus"
#main.tb "!contents? searchFor$"
searchFor$=trim$(searchFor$)
if len(searchFor$)>2 then
cursor hourglass
redim searchList$(500)
for i = 1 to 500 ' so so
if ar$(i)="" then exit for
fileToOpen$= word$(ar$(i),2,chr$(0))
open helpFilePath$;"\";fileToOpen$ for input as #2
contents$ = input$(#2, lof(#2))
'#main.texteditor contents$
if instr(lower$(contents$), lower$(searchFor$)) then
count=count+1
searchList$(count)= ar$(i)
end if
close #2
next i
#main.listbox2 "reload"
cursor normal
else
notice "Please write down more than 2 characters."
end if
end select
end sub
sub lbDoubleClick h2$
#h2$ "selection? selection$"
if selection$ = "" then exit sub
fileToOpen$= word$( selection$,2,chr$(0))
fileToOpen$=replace$( fileToOpen$ , "/", "\" )
run "explorer.exe ";helpFilePath$; "\"; fileToOpen$
'run "htmlviewer.exe ";helpFilePath$;"\";fileToOpen$ - for my personal use- 3rd party app freeware
end sub
function fileExists(path$, filename$)
dim fileExistsInfo$(0,0)
files path$, filename$, fileExistsInfo$()
fileExists = val(fileExistsInfo$(0, 0)) 'non zero is true
end function
function replace$( text$ , this$, tothis$ )
while 1
if instr(text$, this$) then
f = instr(text$, this$)
lenght=len(this$)
text$ = mid$(text$,1,f-1);_
tothis$;mid$(text$,f+lenght)
else
exit while
end if
wend
replace$=text$
end function
sub combosub
end sub
Sub dummy fast$
select case
case fast$ = "#main.button1"
#main.txt1 "!contents? txt$"
#main.txt2 "!contents? theName$"
#main.r1 "value? result$"
if result$="set" then
itag$="["
otag$="]"
closingCode$= "[quit]";chr$(13);_
" close ";txt$;chr$(13);_
" end"
else
closingCode$ = "Sub quit fast$";chr$(13);_
" close #fast$" ;chr$(13);_
" end";chr$(13);_
"End Sub"
end if
#main.combo "selection? sel$"
if instr(sel$,"popup") then
includeButton$= "button ";txt$;".button1 ";chr$(34);_
"&Exit";chr$(34);", "; itag$;"quit";otag$;", ul, 1, 1, 100, 30"
end if
toPrint$ = "WindowWidth = 640 : WindowHeight = 480";chr$(13);_
"UpperLeftX=int((DisplayWidth-WindowWidth)/2)";chr$(13);_
"UpperLeftY=int((DisplayHeight-WindowHeight)/2)";chr$(13);chr$(13);_
includeButton$;chr$(13);chr$(13);_
"Open ";chr$(34);theName$;chr$(34);" for ";sel$; " as ";txt$;chr$(13);_
" ";txt$;" "; chr$(34); "trapclose ";itag$;"quit";otag$; chr$(34);chr$(13);_
"wait";chr$(13);chr$(13);_
closingCode$
#main.ed "!cls"
#main.ed toPrint$
#main.ed "!selectall"
#main.ed "!copy"
#main.ed "!paste"
#main.ed "!origin 0 0"
notice "Code copied to the clipboard!"
end select
End sub
'Carl Gundels dictionary code
[quit.main]
call saveValue
Close #main
END
'enzo's menu code
[onMathRnd] 'Perform action for menu 'Math', item 'rnd('
'Insert your own code here
wait
[onMathVal] 'Perform action for menu 'Math', item 'val('
'Insert your own code here
wait
[onMathNot] 'Perform action for menu 'Math', item 'not('
'Insert your own code here
wait
[onMathSqr] 'Perform action for menu 'Math', item 'sqr('
'Insert your own code here
wait
[onStringsStringInput] 'Perform action for menu 'Strings$', item 'string$ = input$'
'Insert your own code here
wait
[onStringsGlobalize] 'Perform action for menu 'Strings$', item 'Globalize'
'Insert your own code here
wait
[onStringLeft] 'Perform action for menu 'Strings$', item 'Left$( Right$( Word$('
'Insert your own code here
wait
[onStringstmc] 'Perform action for menu 'Strings$', item 'TRIM$( MID$( CHR$('
'Insert your own code here
wait
[onFunctionsFunction] 'Perform action for menu 'Functions', item 'Function('
'Insert your own code here
wait
[onFunctionsFunctionstring] 'Perform action for menu 'Functions', item 'Function$('
'Insert your own code here
wait
[onLoopsForNext] 'Perform action for menu 'Loops', item 'for next'
'Insert your own code here
wait
[onLoopsIfThe] 'Perform action for menu 'Loops', item 'if then var = var + 1 var = x'
'Insert your own code here
wait
[onLoopsWhileWend] 'Perform action for menu 'Loops', item 'while wend'
'Insert your own code here
wait
[notice] 'Perform action for menu 'Loops', item 'do while'
'Insert your own code here
wait
[onLoopsIfThenElse] 'Perform action for menu 'Loops', item 'if then else'
'Insert your own code here
wait
[onLoopsIfThenEndIf] 'Perform action for menu 'Loops', item 'if then end if'
'Insert your own code here
wait
[onINPUTDATAVar] 'Perform action for menu 'INPUT DATA$', item 'Var'
'Insert your own code here
wait
[onINPUTDATAString] 'Perform action for menu 'INPUT DATA$', item 'String$'
'Insert your own code here
wait
[onINPUTDATAArray] 'Perform action for menu 'INPUT DATA$', item 'array$('
'Insert your own code here
wait
[onFileOperationsOpenForInput] 'Perform action for menu 'File Operations', item 'open for input'
'Insert your own code here
wait
[onFileOperationsOutput] 'Perform action for menu 'File Operations', item 'Output'
'Insert your own code here
wait
[onFileOperationsAppend] 'Perform action for menu 'File Operations', item 'Append'
'Insert your own code here
wait
'Carl Gundels dictionary code
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 + 9
pointer = instr(dictionary$, "]~]value]~]", pointer)
key$ = mid$(dictionary$, keyPointer, pointer - keyPointer)
if instr(keyList$, "]~]key]~]" + key$ + "]~]value]~]") = 0 then
getKeys$ = getKeys$ + key$ + delimiter$
keyList$ = keyList$ + "]~]key]~]" + key$
keyCount = keyCount + 1
end if
end if
wend
end function
sub writeDictionary
open categorie$ for output as #writeDict
print #writeDict, dictionary$
close #writeDict
end sub
sub readDictionary
if fileExists(DefaultDir$, categorie$) then
open categorie$ 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 + 9
pointer = instr(dictionary$, "]~]value]~]", pointer)
key$ = mid$(dictionary$, keyPointer, pointer - keyPointer)
if instr(keyList$, "]~]key]~]" + key$ + "]~]value]~]") = 0 then
value$ = getValue$(key$)
newDictionary$ = "]~]key]~]" + key$ + "]~]value]~]" + value$ + newDictionary$
keyList$ = keyList$ + "]~]key]~]" + key$ + "]~]value]~]"
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$+"]~]value]~]")
if keyPosition > 0 then
keyPosition = keyPosition + 9 'skip over key tag
valuePosition = instr(dictionary$, "]~]value]~]", keyPosition)
if valuePosition > 0 then
valuePosition = valuePosition + 11 '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