Handle variables in control definition statements

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

Handle variables in control definition statements

Post by Sparks »

There seems to be some sort of prohibition for using handle variables in control definition statements. For example:

hw$="WIN"
hc$=hc$+".txt"
statictext #hc$, "This is text", x, y, w, h
open "Test Window" for window as #hw$

where x, y, w, h are previously set variables, gives me compile errors on both the statictext and open statements. Replacing the handle variables with literal handles works fine. I can't find any restrictions in either the LB4 or LBB documentation ... but that doesn't mean it isn't there of course. Enlightenment, or a pointer to enlightenment, would be welcome. Best regards
guest
Site Admin
Posts: 197
Joined: Tue Apr 03, 2018 1:34 pm

Re: Handle variables in control definition statements

Post by guest »

Sparks wrote: Sun May 26, 2019 11:57 pmEnlightenment, or a pointer to enlightenment, would be welcome.
If you read the 'Handle Variables' section of the LB4 documentation all should be revealed. There are a number of mistakes in your code:
  1. The first line should be hw$="#WIN". I know that is effectively a duplication of the hash character, but that's how handle variables work.
  2. The second line should be hc$=hw$+".txt". I suspect your original is simply a typo.
  3. Most importantly, in LB4 Handle Variables are only used to reference windows and controls after creation; in LBB it is possible to use them when creating a control but only by using the MAPHANDLE statement.
So your program should have been something like this:

Code: Select all

    nomainwin
    hw$ = "#WIN"
    hc$= hw$ + ".txt"
    textbox #tmp.txt, 10, 10, 280, 200
    open "Test Window" for window as #tmp
    maphandle #tmp.txt, hc$
    maphandle #tmp, hw$
    #hw$ "trapclose [quit]"
    #hc$ "This is some new text in the textbox"
    wait

[quit]
    close #hw$
    end
Sparks
Posts: 10
Joined: Wed Apr 18, 2018 10:07 pm

Re: Handle variables in control definition statements

Post by Sparks »

OK, thanks a bunch. That seems to have fixed that part of my problem ... I say "seems" because I've got at least one other problem getting the code to run which I'm sure is pilot error too.