Page 1 of 1

Defining controls

Posted: Mon Jul 01, 2019 11:20 pm
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.

Re: Defining controls

Posted: Tue Jul 02, 2019 8:29 am
by guest
Sparks wrote:
Mon Jul 01, 2019 11:20 pm
will 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.

Re: Defining controls

Posted: Wed Jul 03, 2019 4:46 pm
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. [:-)

Re: Defining controls

Posted: Wed Jul 03, 2019 5:14 pm
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.