|
Post by xxgeek on Apr 22, 2021 1:14:52 GMT
Putting an A in front of commandlines when putting code into texteditors or listboxes?
Why is this done? Why is it necessary? or is it?
What is the underlying issue with this work around? Can anyone provide some insight on this issue. I have come across some interesting things of late and may have found what's up, but want to hear what others know about this.
Not talking about the jbasic -A switch. An entirely different discussion.
I've heard that the compiler reads this code and chokes without an A in front of commands that go into a texteditor or listbox
|
|
|
Post by tsh73 on Apr 22, 2021 7:37:22 GMT
Hello as I said on another tread I never seen this since 2007. Could you show some examples? As for now, I think adding extra letter in front of command surely make JB not recognize command So no action (except error) are going to happen.
|
|
|
Post by xxgeek on Apr 22, 2021 19:25:27 GMT
I'm not really sure if the following is what people have been referring to when they speak of this "A" in front of commands but I ran into a problem with Carl Gundels Dictionary code while doing some testing on the project I've been working on.
Take the code below tsh73, run it in JB editor and then click on the "New Program button. Paste the code below into the texteditor for the new program when it shows your new program listing in the listbox. You'll see that it corrupts and down't save it properly.
You can make many "New Programs" and save the code with no problems but NOT this code. I don't know the exact reason why, but from what I found when looking into it further through testing is that when it comes across the "delimiter" used in the code, it chokes right there.
It seems that when it reads the same delimiter it is using it freaks out and corrupts the text in the texteditor and doesn't save the text properly to the dictionary.dat file.
I couldn't get it to work until I changed the "delimeter" in the code.
The same thing will happen if you put the code from the "Fast code" "Jbsearch" merge I posted yesterday in the other forum.If you run that code you can put the carl Gundel version into my code, and vice versa, but not into each other. Do some testing. Copy this code into itself when making a new program entry. Do the same for my code posted yesterday. Do the same for my code. Then copy my code into this codes "new program" texteditor. So when enzo mentioned putting an A in front of commands I thought this might be why.
I also wonder if this is the ONLY problem, or will I face more of this from other commands as I do my coding.
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 tsh73 on Apr 23, 2021 6:53:50 GMT
Hello This program keeps all the data in one long string it uses "~key~" as a delimiter what very form "~key~" is selected so 1) resulting string will be human-readable \ modifyable if needed, so no unprintable characters (ASC(<32)) 2) data entered NOT EVER likely have that string inside. And it works, most of the time. But now you add *this program*, that has that word about 10 times. Same things apply to "~value~" Really no wonder things get square. I'm pretty sure it will get weird on any language one can recode that program.
probably way out is using delimiter that is not printable ASC(<32) so in this program it will appear not in literal form but as variable and/ or expression with CHR$() - now this program (any program) will not have exact delimiter in it's text.
But resulting string will not be so easily readable/modifyable.
|
|
|
Post by xxgeek on Apr 23, 2021 11:08:22 GMT
Thanks tsh73, that's exactly what I did. I changed the delimiter in the code I put together because of this problem. It took me a while to figure out what was going on.
Is this why people say to put an A as in a special character A, with the line above it?
Is my code someday going to choke when some one tries to copy a program that has another delimiter? Or any other code I should know about?
|
|
|
Post by tsh73 on Apr 23, 2021 12:58:56 GMT
You really better ask those people, I have no idea ;) But if it coud be printed then someday it can be copied from somewhere If it entered into program code literally (in "") then it's already waiting to be inserted into itself.
I tried to change "~" to chr$(31) everythere. And added (restored?) load on run, so it pick up last dictionary Then I pasted big program other values desappeared - happened than switching from long (big number of lines) to single-line value, scrollbas stays high Fixed that with
#main.value "!origin 1 1" Everything looks OK so far
But I don't like like it always keep items shuffling in a dictionary.
nomainwin WindowWidth = 555 WindowHeight = 438 dim keys$(1000) dim keys$(1000) dim info$(10, 10) global dictionary$, keyCount, lastKey$ '## global keyCode$, valCode$, keyDelim$ '## keyDelim$=chr$(31) keyCode$=keyDelim$+"key"+keyDelim$ valCode$=keyDelim$+"value"+keyDelim$ '//## 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 readDictionary 'you forgot that one? 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$"; #main.value "!origin 1 1" 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$, keyCode$, pointer) if pointer then keyPointer = pointer + 5 pointer = instr(dictionary$, valCode$, pointer) key$ = mid$(dictionary$, keyPointer, pointer - keyPointer) if instr(keyList$, keyCode$ + key$ + valCode$) = 0 then getKeys$ = getKeys$ + key$ + delimiter$ keyList$ = keyList$ + keyCode$ + 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$, keyCode$, pointer) if pointer then keyPointer = pointer + 5 pointer = instr(dictionary$, valCode$, pointer) key$ = mid$(dictionary$, keyPointer, pointer - keyPointer) if instr(keyList$, keyCode$ + key$ + valCode$) = 0 then value$ = getValue$(key$) newDictionary$ = keyCode$ + key$ + valCode$ + value$ + newDictionary$ keyList$ = keyList$ + keyCode$ + key$ + valCode$ end if end if wend dictionary$ = newDictionary$ end sub
sub setValueByName key$, value$ dictionary$ = keyCode$+key$+valCode$+value$+dictionary$ end sub
function getValue$(key$) getValue$ = chr$(0) keyPosition = instr(dictionary$, keyCode$+key$+valCode$) if keyPosition > 0 then keyPosition = keyPosition + 5 'skip over key tag valuePosition = instr(dictionary$, valCode$, keyPosition) if valuePosition > 0 then valuePosition = valuePosition + 7 'skip over value tag endPosition = instr(dictionary$, keyCode$, 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$(keyDelim$) redim keys$(keyCount) for item = 1 to keyCount keys$(item-1) = word$(keyList$, item, keyDelim$) 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 Rod on Apr 23, 2021 15:17:42 GMT
Right still confused. So this A is not really an A it is an A with a line above. That means it is probably a special character and has been choosen because it is unlikely to appear in any text. I cannot find any example of this technique.
But we seem to be talking about code consuming code and both using the same delimiter. If that is the case then it makes no difference if the delimiter is printable or not it is still going to be copied and interpreted.
Surely the trick is to use two separate delimiters. Or change the way the data is stored and stop relying on delimiters.
|
|
|
Post by xxgeek on Apr 23, 2021 16:20:36 GMT
Sorry about the confusion Rod, enzo had mentioned putting the A in front of code earlier. I wanted to know what he meant by it and why it happens but he hasn't been back to explain.
Understood. So the special character or the A thing is not true then. Thanks Rod.
Another question before we end this discussion if I may.
This issue happens when "RUNNING" code reads it's own delimiter. That I have established through hours of frustration,investigation, and testing, and I don't want to go through that again if I can avoid it.
So, can you tell me with all your experience with coding JB is the delimiter the ONLY code to worry about, or am I going to run into problems with other commands, or variables or anything else that will cause corruption in the texteditors or listboxes of my project?
I need to know. I don't want to find out I have wasted weeks, if not months on this just to scrap it.
Thanks again tsh73, and Rod your experience with JB code is very much appreciated. Someday I hope to know as much about the idiosyncrasies of coding in JB.
It's an odd problem. Is it a bug in JB or is this normal for basic interpreters?
|
|
carlg
New Member
Posts: 14
|
Post by carlg on Apr 23, 2021 16:33:34 GMT
What is the problem, precisely? Unless you've discovered a bug in Just BASIC then the problem you're encountering would exist for BASIC in general, and pretty much any programming language.
Also to be clear, Just BASIC isn't really an interpreter. Just BASIC is a compiled language, but it isn't compiled to machine code but to an intermediate form and executed on a virtual machine.
|
|
|
Post by xxgeek on Apr 23, 2021 16:44:17 GMT
If this is Carl Gundel, I was using your Dictionary code to copy some code I was working on. Some of that code had copies of your code re: Dictionary. Try it yourself and see what happens. Use your dictionary to copy its own code into the texeditor after making a "new Key", then make another "new key" and type anything you like into the texteditor.
When the code of dictionary reads the file, it corrupts the data in the listbox, and the data in the texteditor, right when it hits the ~ you used as a delimiter.
|
|
carlg
New Member
Posts: 14
|
Post by carlg on Apr 23, 2021 17:05:41 GMT
If this is Carl Gundel, I was using your Dictionary code to copy some code I was working on. Some of that code had copies of your code re: Dictionary. Try it yourself and see what happens. Use your dictionary to copy its own code into the texeditor after making a "new Key", then make another "new key" and type anything you like into the texteditor. When the code of dictionary reads the file, it corrupts the data in the listbox, and the data in the texteditor, right when it hits the ~ you used as a delimiter. Yeah, that's not surprising really. The dictionary code has its limitations. It is meant as an example to demonstrate some ideas, and you would need to adapt it for your purposes. If ~ is used as a delimiter, then you have to take that into account. Probably the smart thing to do it is to detect it in the input data and then fail gracefully. Maybe I'll write another blog entry about it. Thanks.
|
|
|
Post by tsh73 on Apr 23, 2021 17:27:15 GMT
xxgeek, try my version where chr$(31) inserted instead of "~" I suppose chr$(31) - symbol, not string "chr$(31)" - is not likely to happen in program input (unless you feed it binary files - EXE, pictures etc - but in there no delimiter is safe)
as for
Man, this is PROGRAMMING. You can program whatever your want. Shoot yourself in the foot if you careless, too. There few right paths and uncountable amount of wrong paths. Really, nothing to worry about.
I suppose the fact that folks use JB (and LB) for that long proves it quite robust. There are sure some bugs, but they were discovered and circumvented. To find a new bug needs some special luck. Of cource there are things it can't do - may be not meant to do fisthand - but that's normal. There is no golden hammer, and if tool does not help you you select another one.
You just have to figure out if you really need something out of range of JB capabilities, before your program became too big to abandon.
|
|
|
Post by xxgeek on Apr 23, 2021 17:28:54 GMT
So far Carl, I have passed many a program code into the Dictionary you wrote with no problems at all. It works flawlessly. Only happens when reading it's own code. the fix that works for me is just using a different delimiter. Then the only data that gets corrupted is if I try to copy my own code. not a big problem.
I was more curious if I was going to have other issues similar with any other commands, variables etc in future. At first I though my own coding was the problem so it took me a while to discover what was really going on.
|
|
|
Post by tsh73 on Apr 23, 2021 17:34:33 GMT
it actually IS a problem with CODING but it is Carl's coding.
Or problem with using thing (dictionary code) above limits it supposed to work within. As always, things have limitations. Not having "~key~" in input text is quite reasonable, after some looking into code.
|
|
|
Post by xxgeek on Apr 23, 2021 17:35:36 GMT
tsh73 - I had already found out the issue and used a different delimiter before I posted about the problem, but thanks for delving into this issue. I can continue with my work on Project Organizer as is. Oh, and thanks for letting me know how to get the Ibeam back to the top of the texeditor after a long program entry.I hadn't seen how that is done before and was going to look into it pretty soon. You saved me another few hours
|
|