Defining controls

Discussions about the Liberty BASIC language, with particular reference to LB Booster
Sparks
Posts: 10
Joined: Wed Apr 18, 2018 10:07 pm

Defining controls

Post by Sparks »

dim W$(8) 'contains handle, legend, actionsub, "UL", x, y, w, h
.
call example W$()
.
.
end

sub example X$()
.
.
testvar=3
select case testvar
case 3
hdl$=X$(1)
button , #hdl$, X$(2), X$(3), X$(4), val(X$(5)), val(X$(6)), val(X$(7)), val( X$(8))
case xx
.
.
end select

will not compile, it reports Missing ")" in the "button" line. There are other CASE statements, if I comment out the first one, the next one gives me the same result. My plan was to be able to create a window with various controls, depending on the actions taken in a previous window. I've got to be missing something here [other than a ")", I'm sure they are all paired], it's practically always my fault, usually missing something in the documentation.
guest
Site Admin
Posts: 198
Joined: Tue Apr 03, 2018 1:34 pm

Re: Defining controls

Post by guest »

Sparks wrote: Mon Jul 01, 2019 11:20 pmwill not compile, it reports Missing ")" in the "button" line.
Some parameters of the BUTTON statement are not numerics or strings, and therefore cannot be stored in an array. In particular the action (handler) and anchor parameters aren't: action is the name of a branch label or a SUB, anchor is one of the tokens UL, LL, UR or LR. Both must be specified 'literally'.

So whilst you can successfully put the button text (a string) or its position and size (numerics) in variables or an array, you cannot do the same with the action or anchor.
Sparks
Posts: 10
Joined: Wed Apr 18, 2018 10:07 pm

Re: Defining controls

Post by Sparks »

Thank you. I'll have to rethink my plans here, and just when I thought I'd learned everything about LBB that I could. [:-)
guest
Site Admin
Posts: 198
Joined: Tue Apr 03, 2018 1:34 pm

Re: Defining controls

Post by guest »

Sparks wrote: Wed Jul 03, 2019 4:46 pm I'll have to rethink my plans here
The anchor (which is rarely anything other than UL because of a longstanding bug in LB that causes the control to be mis-positioned) can easily be worked around by using a SELECT CASE statement to select one of the four kinds. The action is not so easily worked around; the best option I can suggest is that you write a common 'action' SUB which all controls share, and in that subroutine vector to the relevant handler routine according to the handle of the control (which is passed to the action SUB as a parameter).

Liberty BASIC lacks the facility which many languages (including some BASICs, like BBC BASIC) have, which is the ability to call a function 'indirectly', i.e. via a pointer rather than by name. That would have solved your problem because you could have passed the pointer in the array, but sadly not.