|
Post by Walt Decker on Oct 16, 2021 12:18:45 GMT -5
To add one more nail to the coffin, folks here have a tendency to not use encapsulated modules, i. e. modules that have their own code space, i. e. subs/functions. Therefore, what if the value of ON Value GOTO does not fall within the scope of 1 to number of branches? Tracing down the error can be a nightmare. (What does one do when one has a nightmare?)
|
|
timur77
Junior Member
Someday I will tell my grandsons that I am older than the Internet. And it will blow their brain.
Posts: 79
|
Post by timur77 on Oct 16, 2021 12:33:14 GMT -5
I also think that "select case" is quite enough for a branched transition (and corresponds to the concept: simple, clear and understandable)
|
|
|
Post by tsh73 on Oct 17, 2021 4:05:28 GMT -5
You guys dramatize situation way out of scope. It's only for better compatibility with old BASIC code. Noone urges you to actually USE it. Besides, GOTO is still very BASIC-like. Like, folks never lived with labels before?
Actually, nothing. I just tested in Qbasic - if value is out of scope, no GOTO get fired (logically, yes?) and execution just continues next statement (consider that "default" branch)
EDIT
but in the contests of "let's cram this game in 1K" this could come handy
|
|
|
Post by dan1101 on Oct 17, 2021 10:07:28 GMT -5
While I agree with all of the views expressed above about Select Case being unquestionably more powerful, there is also something to be said for simplicity. I view "On X Goto " as a simpler, more limited version of the same concept as Select Case when all you want to accomplish is multiple branching without any additional code to be executed. It requires fewer lines of code and is easier to understand at a glance. It could be seen as a kind of shorthand or abbreviated version of Select Case. I love the idea of having branch labels as an option IN ADDITION to line numbers in an "On X Goto", which could become something like: "ON UserInput GOTO [Address.Lookup], [Address.Edit], [Address.Replace], [Address.Delete]" It can be seen as either a logical extension of the "GOTO" statement or a subset of the more powerful Select Case.
|
|
|
Post by tenochtitlanuk on Oct 17, 2021 11:27:59 GMT -5
Sure, add/use 'goto plus labels or line numbers'. I can't get worked up either for or against. But I don't want to debug other peoples' 'write once, read never' code with line numbers and 'goto' structures. Had enough of that in Forth- which is a language I love! As it happens I checked Rosetta Code for LB-unimplemented tasks today, and found a genetic code generate-and-mutate one. So I spent an hour happily doing it. rosettacode.org/wiki/Bioinformatics/Sequence_mutationYou generate a string containing only C, G, T and As, then apply mutation rules. I couldn't resist 'improving' the text-only answers in other languages with a colorful graphic- AND worked in two select/cases! As ever, I'll put my code up on my site in a day or two in case anyone fancies trying the task without preconceptions.Like perhaps an 'on/goto' version!!
|
|
|
Post by tsh73 on Oct 17, 2021 14:45:37 GMT -5
|
|
|
Post by Carl Gundel on Oct 17, 2021 16:20:51 GMT -5
but in the contests of "let's cram this game in 1K" this could come handy LOL. True enough.
|
|
Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Oct 18, 2021 5:37:24 GMT -5
Hi
I have just completed a mammoth conversion of my commercially available software fom another Basic to LB. I had to do some work (not much) to get around some of the other Basic's "non-classic" statements.
In all, I only missed two commands which both exist in the other BASIC and in QBASIC. I missed the one a lot, and the other not so much.
The one I missed the most which required quite a bit of "workaround" was mid$ as a statement and not a function i.e. to be able to use it on the left-side of an equal. Example:
mid$(DataRec$,3,15) = DataField$
I used this a lot in the past to build a "record" rather than resorting to concatenating fields to form one.
Although not as much as the mid$ statement, I missed the string$ function which returns return a string of repeated character. Example to create a string of 40 x "Z":
x$ = string$(40, "Z")
This is handy to initialise a "record" to all characters other than spaces. For spaces, space$(n) works fine. string$ was easy to workaround using a FOR/NEXT loop or string literal but not as neat as just being able to use string$.
Otherwise, LB worked superbly well without having to resort to API's etc.
Regards
Dennis
|
|
|
Post by tenochtitlanuk on Oct 18, 2021 9:21:21 GMT -5
Agree- but easily written as functions. string$ can be defined with that name, but mid$ as a verb has to have a new name. Mid$ as a VERB, ie one that actions a change rather than reporting back part of a string, is implemented in various ways. In your example I assume you are using 15 bytes of the string as a standard-length field. A more common version would replace with however many are needed.
print string$( 40, "?") print insertMid$( "1234567890", 4, "Hi!")
end
function string$( n, c$) for i =1 to n string$ =string$ +c$ next i end function
function insertMid$( c$, p, n$) ' since 'mid$(' is a reserved keyword insertMid$ =left$( c$, p -1) +n$ +mid$( c$, p +len( n$)) end function
???????????????????????????????????????? 123Hi!7890
|
|
Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Oct 20, 2021 0:00:28 GMT -5
Hi Thanks for responding and agreeing! The insertMid$ function is something that I will use in the interim (assuming that LB5 will have mid$ as a statement ) I have added it to my common routines library. Regarding a string$ function, as I wrote in my post, I used a FOR/NEXT workaround using a function exactly as you did. The mid$ workaround you suggested is great, but it would be neater to have mid$ as a statement embedded in the language. It is a statement and function in most BASICs that I have worked with. The string$ command is not that important and the string$ function is adequate as a workaround. Regards Dennis
|
|
Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Oct 27, 2021 8:00:27 GMT -5
Hi
This is probably pushing it but it would be nice to have a "close all" type of statement to close all open files. This is useful when handling a "shutdown" situation where you are not too sure which files are still open. Closing an already closed file generates a "bad handle" error.
It would also be great to have some sort of statement to query if a file is open or not. I am sure the API gurus will have a solution to this but for the sake of portability, an "API-less" solution is preferred. If a "query" statement is made available, a "close all" can be simulated.
Perhaps the above functionality is already in LB 4 but I have not noticed it.
Regards
Dennis
|
|
|
Post by alincon on Oct 27, 2021 10:41:43 GMT -5
Re: open files? You can set a flag right after every open statement and unset it after every close statement. Then query each file's flag to see what files need to be closed at end of program.
r.m.
|
|
|
Post by Brandon Parker on Oct 27, 2021 10:54:04 GMT -5
You can do that in LB...
The only catch is that in a case where the function shown below is encountered while using the Debugger and the file handle does not exist, the Debugger will halt all execution. The Runtime Engine allows the trapping of the error and continuing about you way...
Global False : False = 0 Global True : True = 1
'Let's open a file for input and then close it with our function Open "Your Test File's Complete Path & Name Here" For Input As #myHandle Print safeClose("#myHandle")
'We are not opening anything for #myHandle2 Print safeClose("#myHandle2")
'Let's open the same file again for input and then close it with our function Open "Your Test File's Complete Path & Name Here" For Input As #myHandle Print safeClose("#myHandle")
Wait
Function safeClose(handle$) On Error GoTo [Error] Close #handle$ safeClose = True Exit Function [Error] safeClose = False End Function
{:0)
Brandon Parker
|
|
|
Post by Walt Decker on Oct 27, 2021 11:46:23 GMT -5
I have a DLL that can do that. It also provids the open mode, i. e. input, output, append, random, binary. It also will enumerate the # of files that are open and whether it is actually a file or a device.
|
|
|
Post by alincon on Oct 27, 2021 14:46:51 GMT -5
Walt, that DLL sounds very impressive. Do you have a demo?
r.m.
|
|