Post by xxgeek on Jul 9, 2023 16:53:30 GMT -5
I know there have been others, but do they search and find ALL the help files?
And do they search the Liberty Basic Examples code files as well?
Not sure if I posted this before, but with all the new members I think another post with help search code might help.
Make the tkn and add it to your External Programs list under "RUN" by going to the LB menu under Setup > External Programs >New button and follow instructions.
Have trouble?, just ask in the forums 'novice' section.
Focus is on the textbox, just type and hit [enter]
3, 4 and 5 characters works well
Any issues, please let me know.
If interested a version for Pro could be written, let me know.
And do they search the Liberty Basic Examples code files as well?
Not sure if I posted this before, but with all the new members I think another post with help search code might help.
Make the tkn and add it to your External Programs list under "RUN" by going to the LB menu under Setup > External Programs >New button and follow instructions.
Have trouble?, just ask in the forums 'novice' section.
Focus is on the textbox, just type and hit [enter]
3, 4 and 5 characters works well
Any issues, please let me know.
If interested a version for Pro could be written, let me know.
'Title = Liberty Basic Help Search
'Purpose = Search the Liberty Basic help files, and the Example files for keyword(s)
'_
'Author = xxgeek
'Date April 3 2023
' Instructions
' Just type a keyword and hit [ENTER] - no character minimum (Using 2, 3 and 4 characters works well)
' In the resulting list, click on a title. The help file selected will open in your browser
' When selecting Examples checkbox, the resulting list is example code Titles.
'These Titles open in Liberty Basic IDE
'WARNING - IF / When editting these code examples use "Save As" to avoid corrupting original files
'Help file results start with H_ for Help
'Example results start with CE for Code Example
'First we need the users home path
call getUserPath
'make sure Liberty Basic v4.5.1 is installed
if Version$ <> "4.5.1" then notice "Liberty BASIC 4.5.1 required" : end
WindowWidth = 228 : WindowHeight = 560
UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
dim searchList$(2500), info$(0,0), oneOf$(2500)
global lbPath$, helpFilePath$, fontsize, q$, upath$, temp$
lbPath$ = "c:\Program Files (x86)\Liberty Basic v4.5.1"
lbexe$ = lbPath$;"\liberty.exe"
helpFilePath$ = lbPath$;"\lb4help\LibertyBASIC_4_web"
helpFileMenu$ = "amber_menu.htm"
freeformPath$ = helpFilePath$;"\html\fformhelp"
uAppPath$ = upath$;"\AppData\Roaming\Liberty Basic v4.5.1"
q$ = chr$(34)
'if not exist, copy the users 'lbasic451.ini' file to DefaultDir$ (the dir this file is running from)
'This is done to prevent the "World of Liberty Basic" window, with all the Links from opening
'when a Code file Example is opened in LB the IDE
if fileExists(uAppPath$, "lbasic451.ini") then
if fileExists(DefaultDir$, "lbasic451.ini") = 0 then
open uAppPath$;"\lbasic451.ini" for input as #1
open DefaultDir$;"\lbasic451.ini" for output as #2
#2 input$(#1, lof(#1)) : close #1 : close #2
end if
else
notice "Can't find the lbasic451.ini file = minor problem - continue on" : goto [checkpoint]
end if
[checkpoint]
'Check for lb help files existence - end program if false
if fileExists(helpFilePath$, helpFileMenu$)=0 then notice "Program Terminated";chr$(13) ; "Couldn't find the help files" : end
nomainwin
'Create the form - open the window - set some fonts
textbox #main.tb 0, 0, 170, 20
listbox #main.resultsList, searchList$(, [openFile], 0, 21, 229, 440
checkbox #main.lbHelp, "LB-Help", [lbHelp], [nolbHelp], 10, 470, 70, 20
checkbox #main.lbexamples, "LB-Code Examples", [lbexamples], [nolbexamples], 85, 470, 130, 20
button #main.incFont, "&+", [incFont], UL, 80, 505, 20, 20
button #main.defFont, "&| ", [defFont], UL, 100, 505, 20, 20
button #main.decFont, "&-", [decFont], UL, 120, 505, 20, 20
button #main.default, "GO", [startSearching], UL, 175, 0, 40, 20
open "Search" for dialog_nf as #main
#main "trapclose [quit]"
#main "font Arial 10"
#main.resultsList "singleclickselect"
fontsize = 10
lbHelp = 1 : #main.lbHelp, "set"
wait
'set and reset checkboxes for search categories
[lbHelp] lbHelp = 1 : if contents <> 1 then [search] else wait
[nolbHelp] lbHelp = 0 : if contents <> 1 then [search] else wait
[lbexamples] lbexamples = 1 : if contents <> 1 then [search] else wait
[nolbexamples] lbexamples = 0 : if contents <> 1 then [search] else wait
'resize window font - sets all Listbox fonts equal
[incFont]
fontsize = fontsize + 1 : #main.resultsList "font Arial ";fontsize : goto [search]
[decFont]
fontsize = fontsize - 1 : #main.resultsList "font Arial ";fontsize : goto [search]
[defFont]
fontsize = 10 : #main.resultsList "font Arial ";fontsize : goto [search]
[quit]
close #main
end
'The [Search] button was pressed, or after searching/changing font size etc, the program was directed back here.
[search]
searchFor$ = ""
done = 0
#main.resultsList "select 0" : #main.tb "!setfocus"
#main.tb "!contents? searchFor$"
wait
[startSearching]
#main.tb "!contents? searchFor$"
searchFor$=trim$(searchFor$)
if searchFor$ = "" then notice "No Search Word Detected" : goto [search]
#main.tb "!selectall"
searchList$(1) = " "
searchList$(2) = " "
searchList$(3) = " Searching for "
searchList$(4) = " "
searchList$(5) = " ";upper$(searchFor$)
searchList$(6) = " "
searchList$(7) = " Please Wait"
searchList$(8) = " "
searchList$(9) = " "
searchList$(10) = " "
#main.resultsList "reload"
cursor hourglass
'search lb help files
redim searchList$(2500)
redim oneOf$(2500)
if lbHelp = 1 then
count = 3
files helpFilePath$;"\html", info$()
numFiles = val(info$(0,0 ))
for i = 1 to numFiles
fileToOpen$ = info$(i, 0)
open helpFilePath$;"\html\"; fileToOpen$ for input as #2
contents$ = input$(#2, lof(#2)) : close #2
if instr(lower$(contents$), lower$(searchFor$)) then
x = 1
if lower$(searchFor$) = "and" then oneOf$(count) = "H_AND" : count = count + 1
if lower$(searchFor$) = "not" then oneOf$(count) = "H_NOT" : count = count + 1
if lower$(searchFor$) = "xor" then oneOf$(count) = "H_XOR" : count = count + 1
if lower$(searchFor$) = "or" then oneOf$(count) = "H_OR" : count = count + 1
listName$ = helpFilePath$;"\html\"; fileToOpen$
open listName$ for input as #1 : isOpen = 1
while not(eof(#1))
scan
line input #1, name$
if x = 5 and lower$(left$(name$, 7)) = lower$("<TITLE>") then
name3$ = mid$(name$, 8, len(name$)-15) : if right$(name3$, 4) = "Etc." then name3$ = left$(name3$, len(name3$) - 1)
oneOf$(count) = "H_";name3$ : count = count + 1
end if'
if x = 8 and left$(lower$(name$), 7) = lower$("<TITLE>") then
name5$ = mid$(name$, 8, len(name$)-15)
oneOf$(count) = "H_";name5$ : count = count + 1
end if
if x = 12 and left$(name$ , 5) = "<P><A" then
name8$ = word$(name$, 2, "</A><B>") : name8$ = left$(name8$, len(name8$)-8)
oneOf$(count) = "H_";name8$ : count = count + 1
end if
if x = 14 and left$(name$ , 3) = "<P>" then
name7$ = mid$(name$, 4, len(name$)-7)
oneOf$(count) = "H_";name7$ : count = count + 1
end if
if x = 15 and right$(name$, 8) = "</B></P>" then
name11$ =word$(name$, 2, "B>") : name11$ = left$(name11$, len(name11$)-2)
oneOf$(count) = "H_";name11$ : count = count + 1
exit while
end if
if x = 15 then exit while
x = x + 1
wend
if isOpen = 1 then close #1 : isOpen = 0
end if
next i
end if
'Search the lb Examples Files
if lbexamples = 1 then
files DefaultDir$, "*.bas", info$()
numFiles = val(info$(0,0 ))
for i = 1 to numFiles
fileToOpen$ = info$(i, 0)
open DefaultDir$;"\";fileToOpen$ for input as #2
contents$ = input$(#2, lof(#2)) : close #2
if instr(lower$(contents$), lower$(searchFor$)) then
name$ = upper$(fileToOpen$)
name$ = left$(name$, len(name$)-4)
oneOf$(count) = "CE_";name$ : count = count + 1
end if
next i
end if
'if no search results found
if count - 3 = 0 then
searchList$(1) = " "
searchList$(2) = " "
searchList$(3) = " Nothing found for: "
searchList$(4) = " ";upper$(searchFor$)
searchList$(5) = " "
if lbexamples = 0 then searchList$(6) = " Try adding Examples"
searchList$(7) = " "
if lbexamples = 0 then searchList$(8) = " To the Search Engine"
searchList$(9) = " "
searchList$(10) = " "
#main.resultsList "reload"
cursor normal
goto [doneSearching]
end if
'sort the list of possible results
sort oneOf$(), 3, count
dim b$(count+1)
happened$="|"
K = 0
'filter out the false Titles (Due to differences in html help pages source code - Title not on same line in all files)
for i = 0 to count
name$ = oneOf$(i)
if right$(name$, 1) = ">" or right$(name$, 6) = "window" or left$(name$, 5) = "H_ame" or right$(name$, 8) = "position"_
or left$(name$, 5) = "H_GCO" or right$(name$, 1) = ":" or left$(name$, 3) = "H_<" _
or left$(name$, 3) = "H_"+chr$(39) or right$(name$, 1) = "." or right$(name$, 1) = " " or right$(name$, 8) = "[branch]"_
or right$(name$, 3) = "] )" or right$(name$, 3) = "] ]" or right$(name$, 6) = "items)" or name$ = "H_WHILE...WEND"_
or right$(name$, 5) = "size)" or right$(name$, 1) = ";" or right$(name$, 5) = "LEN=n" or right$(name$, 7) = "number)" _
or right$(name$, 7) = "#handle" or right$(name$, 4) = "varN" or right$(name$, 4) = "...)" or right$(name$, 2) = "];" _
or right$(name$, 1) = "v" or right$(name$, 8) = "fontSpec" or right$(name$, 7) = "expr2 )" or right$(name$, 2) = "))"_
or right$(name$, 12) = "variableName" or right$(name$, 4) = "num2"or right$(name$, 5) = ".bmp"+chr$(34)_
or right$(name$, 2) = chr$(34)+")" or right$(name$, 4) = "var"+chr$(36) or right$(name$, 4) = ",n])"_
or right$(name$, 4) = "expr" or right$(name$, 4) = "num2" or right$(name$, 9) = chr$(34)+"refresh"+chr$(34)_
or right$(name$, 3) = "g])" or right$(name$, 6) = "Label]" or right$(name$, 8) = "#handle)" or right$(name$, 9) = "String$ )"_
or right$(name$, 11) = "Expression)" or right$(name$, 10) = "expression" or right$(name$, 9) = "[number])"_
or right$(name$, 7) = "struct)" or right$(name$, 7) = "comment" or right$(name$, 12) = "recordNumber"_
or right$(name$, 5) = "size)" or right$(name$, 6) = "follow" or right$(name$, 6) = "mode ]" or right$(name$, 8) = "number )"_
or right$(name$, 8) = "[column]" or right$(name$, 10) = "#handle, n" or right$(name$, 2) = " 1" or right$((left$(name$, 7)), 5) = chr$(34)+"Font"_
or right$(name$, 9) = "{LEN = n}" or right$(name$, 5) = "Expr2" or right$(name$, 6) = "length" or mid$(name$, 3, 3) = "var"_
or right$(name$, 10) = "#newHandle" or right$(name$, 12) = "columns rows" or right$(name$, 5) = "Expr$"_
or left$(name$, 4) = "var =" or right$(name$, 6) = "xpr2 )" or left$(name$, 3) = "H_(" or right$(name$, 6) = chr$(34)+"name"+chr$(34) _
or right$(name$, 4) = "#h )" or right$(name$, 9) = "#handle )" or right$(name$, 1) = "€" or right$(name$, 1) = "."_
or name$ = "H_DO LOOP" or name$ = "H_FOR...NEXT" or name$ = "H_IF...THEN" or name$ = "H_Winstring" or right$(name$, 8) = "value"+chr$(34)+" )"_
or right$(name$,1) = "?" or right$(name$,3) = "c$)" or right$(name$,8) = "Keywords" or name$ ="H_BOOLEAN"_
or left$(name$, 3) = "H_&" or word$(name$, 2) = "number" or left$(name$, 11) = "H_Uninstall" or name$ = "H_"_
or name$ = "H_StartupDir" or name$ = "H_EVAL" or name$ = "H_EVAL$" or right$(name$, 4) = "face" or mid$(name$, 3, 3) = "API"_
or name$ = "H_REPLSTR" or name$ = "H_UPPER$(s)" or name$ = "H_LOWER$(s$)" or word$(name$,2) = "name," or word$(name$,2) = "#handle," then
oneOf$(i) = ""
end if
'remove any duplicates from search list (Thanks to tsh73)
if lower$(nameLast$) = lower$(name$) then oneOf$(i) = ""
if instr(happened$, "|";oneOf$(i);"|")=0 then
happened$=happened$;oneOf$(i);"|"
K=K+1: b$(K)=oneOf$(i)
end if
nameLast$ = name$
next i
'Create final list of search results
for x = 0 to K
if lower$(word$(b$(x), 2, "_")) = lower$(searchFor$) then match$ = b$(x)
if instr(lower$(b$(x)), lower$(searchFor$)) _
and lower$(mid$(b$(x), 3, len(searchFor$))) = lower$(searchFor$)_
or lower$(mid$(b$(x), 4, len(searchFor$))) = lower$(searchFor$) then_
searchList$(u+3) = b$(x) : u = u+1
next x
for t = 0 to K
if instr(lower$(b$(t)), lower$(searchFor$)) then
if lower$(mid$(b$(t), 3, len(searchFor$))) <> lower$(searchFor$)_
and lower$(mid$(b$(t), 4, len(searchFor$))) <> lower$(searchFor$) then
searchList$(u+v+10) = b$(t) : v = v+1
end if
end if
next t
for a = 0 to K
if not(instr(lower$(b$(a)), lower$(searchFor$))) then_
searchList$(u+v+w+17) = b$(a) : w = w+1
next a
'manage the headers
if u+v <> 0 then searchList$(0) = u+v;" Titles Containing ";q$;upper$(searchFor$);q$
if u+v = 0 then searchList$(0) = " No Titles Found for ";q$;upper$(searchFor$);q$';" Found"
searchList$(1) = " "
if v <> 0 then searchList$(2) = " ";u;" Top Picks For ";q$;upper$(searchFor$);q$
searchList$(u+5) =" "
if v <> 0 then searchList$(u+6) = " ";v;" Remaining Titles "'
if v <> 0 then searchList$(u+7) =" "
if v <> 0 then searchList$(v+u+13) = " "
if w-2 <> 0 then searchList$(v+u+14) = " ";w-2;" Other Pages "
if u+v = 0 then searchList$(v+u+14) = " ";w-2;" Pages Containing ";upper$(searchFor$)
searchList$(v+u+15) = " "
searchList$(v+u+w+29) = " "
searchList$(v+u+w+30) = " If you need more information "
searchList$(v+u+w+31) = " on "
searchList$(v+u+w+32) = " Liberty Basic v4.5.1 Coding "
searchList$(v+u+w+33) = " Please Visit"
searchList$(v+u+w+34) = " The Liberty Basic Forums "
searchList$(v+u+w+35) = " @ "
searchList$(v+u+w+36) = "https://libertybasiccom.proboards.com/"
searchList$(v+u+w+37) = " "
searchList$(v+u+w+38) = " "
'if there is a match with the search result
if match$ <> "" then searchList$(1) = " 1 Match "
#main.resultsList "reload"
'finished displaying results - reset variables - cursor back to normal
[doneSearching]
u = 0 : v = 0 : w = 0 : match$ = ""
cursor normal
goto [search]
'One of the Help Search results was Selected - Open the Help File in user's default browser
[openFile]
if lbHelp = 1 then
#main.resultsList "selection? selectionH$"
selectionH$ = right$(selectionH$, len(selectionH$) - 2)
if selectionH$ = "XOR" or selectionH$ = "AND" or selectionH$ = "NOT" or selectionH$ = "OR" then
run "explorer.exe ";helpFilePath$;"\html\libe0azy.htm"
goto [search]
end if
files helpFilePath$;"\html", info$()
numFiles = val(info$(0,0 ))
for i = 1 to numFiles
fileToOpen$ = info$(i, 0)
open helpFilePath$;"\html\";fileToOpen$ for input as #3
contents$ = input$(#3, lof(#3)) : close #3
if instr(lower$(contents$), lower$("<title>";selectionH$;"</TITLE>")) then
if fileToOpen$ = "idecode451.html" then fileToOpen$ = "libe0ze8.htm"
run "explorer.exe ";helpFilePath$;"\html\";fileToOpen$ : done = 1
if done = 1 then exit for
else
if done = 1 then goto [search]
if instr(lower$(contents$), lower$("</A><B>";selectionH$;"</B></P>")) then
run "explorer.exe ";helpFilePath$;"\html\";fileToOpen$ : done = 1
if done = 1 then exit for
end if
end if
next i
if done = 1 then done = 0 : goto [search]
end if
'if a Code Example file was selected
if lbexamples = 1 then
#main.resultsList "selection? selectionCE$"
selectionCE$ = right$(selectionCE$, len(selectionCE$) - 3)
if fileExists(DefaultDir$, selectionCE$;".bas") then
run lbexe$;" ";DefaultDir$;"\";selectionCE$;".bas" : goto [search]
end if
end if
#main.resultsList "selection? selection$"
if selection$ = "https://libertybasiccom.proboards.com/" then run "explorer ";selection$ : goto [search]
'get users homepath = aka %userprofile% = "c:\users\xxxxx" (5 characters long normally Win 10)
sub getUserPath
run "cmd.exe /c echo %userprofile% >UserHomePath.txt", HIDE
do
scan
loop until fileExists(DefaultDir$, "UserHomePath.txt")
open "UserHomePath.txt" for input as #1
upath$ = input$(#1, lof(#1))
close #1
if upath$ = "" then notice "Sorry, can't find user path " : end
kill DefaultDir$;"\UserHomePath.txt"
end sub
'create a pause subroutine
sub pause mil
t=time$("ms")+mil
while time$("ms")<t
scan
wend
end sub
'Verify file existence function
function fileExists(path$, filename$)
dim fileExistsInfo$(0,0)
files path$, filename$, fileExistsInfo$()
fileExists = val(fileExistsInfo$(0, 0)) 'non zero is true
end function
'