|
Post by cundo on Apr 16, 2021 17:12:18 GMT
filedialog "bas", "*.bas", file$ filemax = 5000 'max number of lines of working program dim array$(filemax) nomainwin
WindowWidth = 544 WindowHeight = 375
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
listbox #m.l, array$(, [click], 6, 11, 488, 280 listbox #m.l2, array$(, [click], 6, 11, 488, 280 open "ListBoxIDE" for dialog_nf as #m print #m, "trapclose [quit.m]" print #m.l, "singleclickselect" print #m, "font ms_sans_serif 19"
if file$="" then notice "No file!" goto [quit.m] end if dim program$(filemax) open file$ for input as #file while not(eof(#file)) line input #file, program$(i) i=i+1 wend close #file
for x = 1 to i
array$(x) = program$(x)
next x
'display [reload] if toggle = 0 then
print #m.l, "hide" print #m.l2, "show" print #m.l2, "reload"
else
print #m.l, "show" print #m.l2, "hide" print #m.l, "reload" rint #m.l, "selectionindex? index" wait
[click] if toggle = 0 then print #m.l2, "selectionindex? index" else print #m.l, "selectionindex? index" end if string$ = array$(index) newcode$ = string$ prompt string$; newcode$ if newcode$ = "" then [reload] array$(index) = newcode$ index = 0 newcode$ = "" goto [reload]
[quit.m] close #m end
This verison has an 'editable' type input, allowing for a "mouse scroll" between inputs, and needs double click toggled to single; every other input. That code doesn´t work for me as is, because it has some tipos Enzo.
|
|
|
Post by xxgeek on Apr 18, 2021 1:33:52 GMT
It was a "p" missing in a print statement and a missing "end if" later in the code.
filedialog "bas", "*.bas", file$ filemax = 5000 'max number of lines of working program dim array$(filemax) nomainwin WindowWidth = 544 WindowHeight = 375 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) listbox #m.l, array$(, [click], 6, 11, 488, 280 listbox #m.l2, array$(, [click], 6, 11, 488, 280 open "ListBoxIDE" for dialog_nf as #m print #m, "trapclose [quit.m]" print #m.l, "singleclickselect" print #m, "font ms_sans_serif 19"
if file$="" then notice "No file!" goto [quit.m] end if dim program$(filemax) open file$ for input as #file while not(eof(#file)) line input #file, program$(i) i=i+1 wend close #file
for x = 1 to i array$(x) = program$(x) next x
'display [reload] if toggle = 0 then print #m.l, "hide" print #m.l2, "show" print #m.l2, "reload" else print #m.l, "show" print #m.l2, "hide" print #m.l, "reload" end if print #m.l, "selectionindex? index" wait
[click] if toggle = 0 then print #m.l2, "selectionindex? index" else print #m.l, "selectionindex? index" end if string$ = array$(index) newcode$ = string$ prompt string$; newcode$ if newcode$ = "" then [reload] array$(index) = newcode$ index = 0 newcode$ = "" goto [reload]
[quit.m] close #m end
|
|
|
Post by xxgeek on Apr 18, 2021 1:38:25 GMT
I've read this before in many places. Why is this? Has anyone ever delved into why? Has anyone ever solved this mystery?
|
|
|
Post by tsh73 on Apr 18, 2021 5:07:48 GMT
I pretty sure I never seen that statement since 2007 on forums. Or never paid attention to. Is it real? If real, how it supposed to be used?
|
|
|
Post by Rod on Apr 18, 2021 6:35:00 GMT
Are we talking about the A switch? Pretty sure it is in the section about using another editor. A switch automatically closes on completion.
|
|
|
Post by xxgeek on Apr 22, 2021 5:12:58 GMT
Are we talking about the A switch? Pretty sure it is in the section about using another editor. A switch automatically closes on completion. No Rod, it's not about the jbasic -A switch at all. Just a coincidence they both have a letter A Not about Alabama either (I hope you have a sense of humor Rod) It's about the problem of copying JB programming code to or from a variable and or a file to or from a texteditor in JB code. Not sure if it's when written, or when it's read. The code gets corrupted in the texteditor, and the file it creates. It all depends on the actual code being copied. @ enzo --- Thanks for all the work you have done to get this going enzo. Your code has flaws, but not anything I couldn't deal with. The code below is a small part of what I want for the Project Organizer app I've been working on. The dictionary code was from Carl Gundels blog. I would like to have at least 3 more of these open in the same window, reusing the same functions etc. But I'm still not there yet. One for Programs. one for examples, one for Guides, and one for commands & syntax. If you know how to do that, let me know ok. With the code I hope will work, we can ALL (everyone who uses it) can swap dat files to make a great app for JB users new and old alike. cundo -- I've asked a few times about getting your permission with no answer from you. If you are ignoring me, ok fine I can deal with that. The code posted here in the forums is publicly available. My code, along with all the code I have collected is just sitting in these forums doing nothing but looking pretty. It's about time we gathered it up and made a useful app to promote and showoff Just Basic. if Just Basic doesn't get many more users, there may never be another update. Let's all work together to make sure that never happens. Also, if you would like to help me out I would like to expand your search engine to include the Tutorial and as we progress I want to search the files we create with this code. If you don't want to do it, I will, eventually. Here is a piece of what I have been working on. To be expanded on when I have time to look into it.My code has 4 of the dictionaries on it with buttons to copy code , run code, and add new commands, examples, guides and programs. I would post all I have, but it's not functioning yet. So I tore out what works and left out many of the details already coded. I really like what you did with this search app and would love to have you with us on this. Once my actual code is functional all we'll need to do is copy paste and create. Also, I am adding this to Project Organizer so when a Project is creating a tkn file, it automatically adds th .bas file code to thjis Programs list. PO will also have a Preferences page, possibly with Profiles, but many other additions as well. Come on guys, lets do this, and make Just Basic the basic everyone uses. At the very least, we may just get a less buggy Just Basic out of it if Carl Gundel appreciates the efforts made, and the fact that we do this for no monetary gain whatsoever. Anyone can write snippets al day long, but it takes special people to make great apps. Thanks for reading, and thanks for everything you've all done so far to help Just Basic users learn the Just Basic way. btw - Project organizer is now over 1000 lines long. One more thing - Don't use this code to copy this code. I know some of you will try it, and you'll find out what is meant by "put an A" in front of command lines. 'Dictionary code from Carl Gundels blog. https://basicprogramming.blogspot.com ' 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
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
dim keys$(1000) dim info$(10, 10) global helpFilePath$, dictionary$, keyCount, lastKey$ call readDictionary 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 = 690 WindowHeight = 720 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 from Carl Gundel's blog 2006 texteditor #main.value, 170, 390, 500, 260 listbox #main.keys, keys$(), [keySelected], 5, 390, 160, 160 button #main.newprogramButton, "New Program", [newprogram], UL, 35, 560, 90, 20 statictext #main.programsText, "Programs", 50, 365, 80, 25 statictext #main.programscodeText, "Program Code", 320, 365, 110, 20
'jbsearch code statictext #main.searchjbText, "Search the JB Help Files", 450, 10, 200, 30 listbox #main.listbox1, ar$(, lbDoubleClick, 430, 85, 240, 280 textbox #main.tb, 430, 72, 148, 30 listbox #main.listbox2, searchList$(, lbDoubleClick, 430, 105, 240, 280 button #main.contents, "&Contents", buttonClick, UL, 425, 40, 80, 30 button #main.search, "&Search", buttonClick, UL, 515, 40, 90, 30 button #main.help, "?", buttonClick, UL, 615, 40, 26, 30 button #main.default, "&Go", buttonClick, UL, 590, 70, 30, 32
'fastcode code statictext #main.windowType, "Window Type", 10, 92, 90, 20 statictext #main.makewindowhells, "Make Window Shells", 150, 10, 150, 30 texteditor #main.ed, 8, 150, 400, 170 statictext #main.st1, "< Name && Handle >", 155, 48, 128, 20 textbox #main.txt1, 300, 46, 100, 25 textbox #main.txt2, 30, 46, 100, 25 button #main.button1, "Generate Code", dummy, ul, 110, 330, 200, 20 combobox #main.combo, br$(, dummy, 110, 85, 222, 20 checkbox #main.r1, "Use Branches instead of Subs", dummy, dummy, 8, 120, 222, 20
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! menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "JB Search v1.02 and Fast Start v1.01, by cundo" for window as #main #main "trapclose [quit]" #main.searchjbText, "!font arial black 14 bold" #main.makewindowhells, "!font arial 14 bold" #main.listbox1 "singleclickselect" #main.listbox2 "singleclickselect" #main.listbox1 "font arial black 8 bold" #main.listbox2 "font arial black 8 bold" #main.listbox2 "hide" : #main.tb "!hide" : #main.default "!hide"
#main "font arial 10 bold" #main.txt1 "#main" #main.txt2 "untiltled" #main.r1 "set" #main.ed "!font arial 8 bold" #main.combo "selectindex 1" 'dictionary code from Carl Gundels blog 2006 #main.keys "singleclickselect" #main.value "!autoresize"; call loadKeys wait
[main.inputLoop] 'wait here for input event wait
[newKey] 'ask the user for a new key call saveValue prompt "Enter a name for the Program."; 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
[keySelected] 'a key in the list was selected call saveValue #main.keys "selection? selectedKey$" selectedValue$ = getValue$(selectedKey$) #main.value "!contents selectedValue$"; lastKey$ = selectedKey$ wait
[newprogram] goto [newKey]
[quit] 'End the program call saveValue close #main end
'jbsearch code by cundo instructions$ = "Select an item from the ";_ "list to view the article on your web browser."
sub buttonClick h2$ select case word$(h2$,2,".") case "contents" #main.listbox1 "show" : #main.listbox2 "hide" : #main.tb "!hide" :#main.default "!hide" case "search" #main.listbox1 "hide" : #main.listbox2 "show" : #main.tb "!show" : #main.default "!show" #main.tb "!setfocus" 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 "default" #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$ 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
'menu created by enzo
[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
'code from Carl Gundels Dictionary at his blog site. https://basicprogramming.blogspot.com/ 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$ + "~value~") = 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~" + 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 + 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
|
|
|
Post by tsh73 on Apr 22, 2021 8:15:53 GMT
Run this under Win10
clicking help topic just opens My Documents folder It looks like here's the problem:
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" first part of path has "\" in the end, second has "\" in front. So we have "\\". Removing extra "\" made help topic open in browser.
Generate code button named it
it said it copied code to clipboard - I run JB and pasted - it did work
Suggestion: add a chekbox for NOMAINWIN
|
|
|
Post by xxgeek on Apr 22, 2021 19:49:49 GMT
When I posted this I had to edit out the htmlviewer I use. I forgot to fix the path, so the extra \ got left behind. Sorry about that. The "untitled" is what you get if you don't enter a "name"' Did you enter a "name" ? Anyway, that's cundo's code. Take it up with him jk Didn't know that was possible. Got a howto handy?
|
|
|
Post by Rod on Apr 22, 2021 20:06:46 GMT
This is all too cryptic and hard to follow. I have never heard of the need for an A. The only issue with copying code is if the internet source supports hard space characters and Just Basic is not set up to filter them out. Go to Preferences and see if Filter Bad Characters is ticked. If not tick it, restart Just Basic and try again.
If that does not help we need to get a little more specific and show the problem with a single textbox or texteditor and a single source to copy that consistently shows the problem.
The code seems to copy on my system but I am not sure I am following the fault correctly.
|
|
|
Post by xxgeek on Apr 22, 2021 20:07:08 GMT
The code works fine in Linux with or without the extra \ but not in Win 10 Learn something new everyday about the details of coding JB in both Linux and Windows.
I edited the code above and took the extra \ out.
Thanks for the info tsh73
|
|
|
Post by xxgeek on Apr 22, 2021 20:15:19 GMT
This is all too cryptic and hard to follow. I have never heard of the need for an A. The only issue with copying code is if the internet source supports hard space characters and Just Basic is not set up to filter them out. Go to Preferences and see if Filter Bad Characters is ticked. If not tick it, restart Just Basic and try again. If that does not help we need to get a little more specific and show the problem with a single textbox or texteditor and a single source to copy that consistently shows the problem. The code seems to copy on my system but I am not sure I am following the fault correctly. Take this code from Carl Gundels blog, clean not editted. Run it in JB. Make a "new program" using the button on the lower leftlistbox. paste this code into the textbox. If it doesn't corrupt the entry right away, try making another "new program" and then go back to your first entry in the listbox and see the corruption. Same thing would happen if you try to do that with my editted code. But if you use my code in Carls clean unedted version it will not corrupt and vice versa. 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 collectGarbage 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$ + "~value~") = 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~" + 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 + 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
|
|
|
Post by xxgeek on Apr 22, 2021 20:20:34 GMT
P/S. When the code reading the file reaches the "delimeter" in the code it is reading it chokes.
|
|
|
Post by Rod on Apr 23, 2021 9:11:09 GMT
I can't find any code on the thread that gives me
|
|
|
Post by tsh73 on Apr 23, 2021 10:16:57 GMT
>>The "untitled" is what you get if you don't enter a "name" but it says "untiltled"
, see extra L?
|
|
|
Post by xxgeek on Apr 23, 2021 10:52:05 GMT
I can't find any code on the thread that gives me Sorry about that Rod. Two threads on the same ttopic. The code below is my code. Make a "new key" on Carls running code paste my code into the texeditor (bottom right) to save it. Make another "new key" It works. Now try copying Carls code into the texteditor in his own "RUNNING" code and see what happens. If nothing happens, try making another "new Key" from his menu and see what happens. What happens is when the "RUNNING" code reads it's own Delimiter it corrupts the list, and the data. So what I had to do was change the delimiter in my code so it didn't match Carls to make it work in order to copy Carls code with my app. @ tsh73 - Ok, I see what you mean now. Fixed in the code below and above in 2 seconds from now.. 'Dictionary code from Carl Gundels blog. https://basicprogramming.blogspot.com/ ' 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
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
dim keys$(1000) dim info$(10, 10) global helpFilePath$, dictionary$, keyCount, lastKey$ call readDictionary 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 = 690 WindowHeight = 720 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 from Carl Gundel's blog 2006 texteditor #main.value, 170, 390, 500, 260 listbox #main.keys, keys$(), [keySelected], 5, 390, 160, 160 button #main.newprogramButton, "New Program", [newprogram], UL, 35, 560, 90, 20 statictext #main.programsText, "Programs", 50, 365, 80, 25 statictext #main.programscodeText, "Program Code", 320, 365, 110, 20
'jbsearch code statictext #main.searchjbText, "Search the JB Help Files", 450, 10, 200, 30 listbox #main.listbox1, ar$(, lbDoubleClick, 430, 85, 240, 280 textbox #main.tb, 430, 72, 148, 30 listbox #main.listbox2, searchList$(, lbDoubleClick, 430, 105, 240, 280 button #main.contents, "&Contents", buttonClick, UL, 425, 40, 80, 30 button #main.search, "&Search", buttonClick, UL, 515, 40, 90, 30 button #main.help, "?", buttonClick, UL, 615, 40, 26, 30 button #main.default, "&Go", buttonClick, UL, 590, 70, 30, 32
'fastcode code statictext #main.windowType, "Window Type", 10, 92, 90, 20 statictext #main.makewindowhells, "Make Window Shells", 150, 10, 150, 30 texteditor #main.ed, 8, 150, 400, 170 statictext #main.st1, "< Name && Handle >", 155, 48, 128, 20 textbox #main.txt1, 300, 46, 100, 25 textbox #main.txt2, 30, 46, 100, 25 button #main.button1, "Generate Code", dummy, ul, 110, 330, 200, 20 combobox #main.combo, br$(, dummy, 110, 85, 222, 20 checkbox #main.r1, "Use Branches instead of Subs", dummy, dummy, 8, 120, 222, 20
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! menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "JB Search v1.02 and Fast Start v1.01, by cundo" for window as #main #main "trapclose [quit]" #main.searchjbText, "!font arial black 14 bold" #main.makewindowhells, "!font arial 14 bold" #main.listbox1 "singleclickselect" #main.listbox2 "singleclickselect" #main.listbox1 "font arial black 8 bold" #main.listbox2 "font arial black 8 bold" #main.listbox2 "hide" : #main.tb "!hide" : #main.default "!hide"
#main "font arial 10 bold" #main.txt1 "#main" #main.txt2 "untitled" #main.r1 "set" #main.ed "!font arial 8 bold" #main.combo "selectindex 1" 'dictionary code from Carl Gundels blog 2006 #main.keys "singleclickselect" #main.value "!autoresize"; call loadKeys wait
[main.inputLoop] 'wait here for input event wait
[newKey] 'ask the user for a new key call saveValue prompt "Enter a name for the Program."; 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
[keySelected] 'a key in the list was selected call saveValue #main.keys "selection? selectedKey$" selectedValue$ = getValue$(selectedKey$) #main.value "!contents selectedValue$"; lastKey$ = selectedKey$ wait
[newprogram] goto [newKey]
[quit] 'End the program call saveValue close #main end
'jbsearch code by cundo instructions$ = "Select an item from the ";_ "list to view the article on your web browser."
sub buttonClick h2$ select case word$(h2$,2,".") case "contents" #main.listbox1 "show" : #main.listbox2 "hide" : #main.tb "!hide" :#main.default "!hide" case "search" #main.listbox1 "hide" : #main.listbox2 "show" : #main.tb "!show" : #main.default "!show" #main.tb "!setfocus" 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 "default" #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 "htmlviewer.exe ";helpFilePath$;"\";fileToOpen$ 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
'menu created by enzo
[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
'code from Carl Gundels Dictionary at his blog site. https://basicprogramming.blogspot.com/ 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$ + "~value~") = 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~" + 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 + 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
|
|