LB Booster
Programming >> Liberty BASIC language >> Liberty BASIC v4.5 (Beta 3)
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1415835384

Liberty BASIC v4.5 (Beta 3)
Post by Richey on Nov 12th, 2014, 10:36pm

Richard, I understand that you will not update LBB with some of the new in-built functions found in LB v4.5 (Beta 3) in order to avoid adding unnecessary 'bloat' to LBB.

Would you instead be able to publish equivalent user-defined functions for some of the new features found in LB v4.5 (Beta 3)?

Thank you in advance.


Re: Liberty BASIC v4.5 (Beta 3)
Post by Richard Russell on Nov 13th, 2014, 09:35am

on Nov 12th, 2014, 10:36pm, Richey wrote:
Would you instead be able to publish equivalent user-defined functions for some of the new features found in LB v4.5 (Beta 3)?

I'm mystified that Carl thinks the new string manipulation functions are worthwhile, when they can be trivially implemented as user-defined functions. I would far rather he had spent the time fixing bugs and/or adding features that genuinely extend the capabilities of LB (LBB should have given him some ideas!).

Anyway, here are replacements which should work in LB 4.04 and LBB:

Code:
function upto$(sourceString$, search$)
i = instr(sourceString$, search$)
if i then upto$=left$(sourceString$,i-1) else upto$=sourceString$
end function

function after$(sourceString$, search$)
i = instr(sourceString$, search$)
if i then after$ = mid$(sourceString$,i+len(search$))
end function

function afterlast$(sourceString$, search$)
do : i = j
  j = instr(sourceString$, search$, j+1)
loop until j = 0
if i then afterlast$ = mid$(sourceString$,i+len(search$))
end function

function endswith(sourceString$, search$)
endswith = right$(sourceString$,len(search$)) = search$
end function

function remchar$(sourceString$, removeThese$)
remchar$ = sourceString$
for i = 1 to len(removeThese$)
  do
    j = instr(remchar$, mid$(removeThese$,i,1))
    if j then remchar$ = left$(remchar$,j-1);mid$(remchar$,j+1)
  loop until j = 0
next
end function 

Richard.

Re: Liberty BASIC v4.5 (Beta 3)
Post by tsh73 on Nov 13th, 2014, 8:16pm

LOL
me guess that Carl work[ed] on something benefiting faster string functions.
Anyway, thanks for UDF - I'll save this little snippet for using with JB (likely, I will end porting something something LB45 to JB)
Re: Liberty BASIC v4.5 (Beta 3)
Post by Richard Russell on Nov 13th, 2014, 9:39pm

on Nov 13th, 2014, 8:16pm, tsh73 wrote:
me guess that Carl work[ed] on something benefiting faster string functions.

Certainly the native remchar$ in LB 4.5 is a lot faster than the equivalent UDF:
(note that in this case LBB runs more than 30 times faster than LB 4.04!!).

But the other functions don't show a significant speed benefit, for example after$:
(there's little difference between the native function and the UDF when running in LB, but LBB is 8 times faster).

Richard.

Re: Liberty BASIC v4.5 (Beta 3)
Post by Richey on Nov 15th, 2014, 06:43am

on Nov 13th, 2014, 09:35am, Richard Russell wrote:
I'm mystified that Carl thinks the new string manipulation functions are worthwhile, when they can be trivially implemented as user-defined functions. I would far rather he had spent the time fixing bugs and/or adding features that genuinely extend the capabilities of LB (LBB should have given him some ideas!).

Anyway, here are replacements which should work in LB 4.04 and LBB:

Code:
function upto$(sourceString$, search$)
i = instr(sourceString$, search$)
if i then upto$=left$(sourceString$,i-1) else upto$=sourceString$
end function

function after$(sourceString$, search$)
i = instr(sourceString$, search$)
if i then after$ = mid$(sourceString$,i+len(search$))
end function

function afterlast$(sourceString$, search$)
do : i = j
  j = instr(sourceString$, search$, j+1)
loop until j = 0
if i then afterlast$ = mid$(sourceString$,i+len(search$))
end function

function endswith(sourceString$, search$)
endswith = right$(sourceString$,len(search$)) = search$
end function

function remchar$(sourceString$, removeThese$)
remchar$ = sourceString$
for i = 1 to len(removeThese$)
  do
    j = instr(remchar$, mid$(removeThese$,i,1))
    if j then remchar$ = left$(remchar$,j-1);mid$(remchar$,j+1)
  loop until j = 0
next
end function 

Richard.


Thank you Richard. Your work is very much appreciated.

Re: Liberty BASIC v4.5 (Beta 3)
Post by Richard Russell on Nov 17th, 2014, 11:25am

Another issue with adding the new native functions is that their names (upto$, after$ etc.) become invalid names for user-defined functions or arrays. So any existing program which happens to contain a function or array with one of those names - or indeed a program using one or more of my UDF replacements - will fail to compile.

Fortunately if you're an LBB user there's a workaround - put the UDFs I've listed above in a separate file which you 'include' in your program. Then when run in LB 4.5 the 'include will be ignored and the native function(s) used, whereas in LBB the 'include will be actioned and the user-defined function(s) used.

Richard.

Re: Liberty BASIC v4.5 (Beta 3)
Post by Richard Russell on Nov 21st, 2014, 5:39pm

A fundamental requirement of a typical Windows application is that anything that can be done using the mouse has a keyboard equivalent. For example menu selections can be made using Alt-key shortcuts, and the 'right click' context menu can be brought up by pressing Shift+F10. This can be particularly important for users with disabilities.

I have been trying to find a keyboard equivalent for the new Ctrl+left-click navigation aid in LB 4.5, which allows you to jump directly to a label, subroutine or function in the program. But I can't find a way of doing it without the mouse. Does anybody know if it is possible? The 'disability discrimination' campaigners won't be happy if it isn't. sad

Richard.
Re: Liberty BASIC v4.5 (Beta 3)
Post by Richard Russell on Jan 6th, 2015, 1:23pm

on Nov 13th, 2014, 09:35am, Richard Russell wrote:
Anyway, here are replacements which should work in LB 4.04 and LBB:

Carl is now proposing that yet another (in my opinion unnecessary) native string function be added to LB 4.5: replstr$. Here is a user-defined function which provides the same functionality:

Code:
FUNCTION replstr$(s$, search$, replace$)
    DO
      i = INSTR(s$, search$, i)
      IF i THEN
        s$ = LEFT$(s$, i - 1); replace$; MID$(s$, i + LEN(search$))
        i = i + LEN(replace$)
      END IF
    LOOP UNTIL i = 0
    replstr$ = s$
END FUNCTION 

As discussed previously, to maintain the best compatibility between LBB and LB4.5 put the replacement string functions in a separate file (e.g. strfuncs.bas) and 'include that in your program's code.

When running in LB 4.5 the 'include will be ignored and the new native functions will be used, and when running in LBB the 'include will be actioned and the UDF versions will be used instead.

Richard.