Page 1 of 1

Handle variables in control definition statements

Posted: Sun May 26, 2019 11:57 pm
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

Re: Handle variables in control definition statements

Posted: Mon May 27, 2019 9:27 am
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

Re: Handle variables in control definition statements

Posted: Mon May 27, 2019 7:59 pm
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.