LB Booster
Programming >> Liberty BASIC language >> Handle variables in maphandle
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1520380024

Handle variables in maphandle
Post by k6dgw on Mar 6th, 2018, 10:47pm

Are handle variables valid in maphandle?

textbox #X.tmp, x, y, w, h
newh$="#Win.rc"+str$(row)+str$(col)
maphandle #X.tmp #newh$

gives me a type mismatch on the maphandle line

Fred
Re: Handle variables in maphandle
Post by Richard Russell on Mar 7th, 2018, 08:33am

on Mar 6th, 2018, 10:47pm, k6dgw wrote:
Are handle variables valid in maphandle?

Of course; in fact MAPHANDLE would hardly be useful at all if that wasn't the case. The error in your code is that you have a spurious hash symbol prefixing the second parameter; it should be:

Code:
    textbox #X.tmp, x, y, w, h
    newh$="#Win.rc"+str$(row)+str$(col)
    maphandle #X.tmp, newh$ 

The two forms of MAPHANDLE are:

Code:
    MAPHANDLE #oldhandle, #newhandle
    MAPHANDLE #oldhandle, newhandle$ 

Richard.

Re: Handle variables in maphandle
Post by Rod on Mar 7th, 2018, 12:02pm

Fred is thinking about the #handleVariable concept.

Code:
nomainwin

textbox #t.txt, 20, 40, 260, 25
WindowWidth = 350 : WindowHeight = 190
open "Simple text box" for window as #t
#t "trapclose [quit]"

h$="#t.txt"
#h$ "hello"

new$="#t.txt2"
maphandle #t.txt, #new$ 

#new$ "again"
wait

[quit]
close #t
end 

Re: Handle variables in maphandle
Post by Richard Russell on Mar 7th, 2018, 12:49pm

on Mar 7th, 2018, 12:02pm, Rod wrote:
Fred is thinking about the #handleVariable concept.

It's true that LB is somewhat inconsistent in its handle variable syntax, which is probably what led him astray. When you are accessing a control using a handle variable you must add a hash prefix:

Code:
    #handlevariable$ "Command string" 

(this means you effectively have two hashes: an explicit one as shown and another in the handle variable string).

However in the MAPHANDLE statement you must not add a hash prefix to the handle variable:

Code:
    MAPHANDLE #oldhandle, newhandle$ 

Although this is clearly documented in the LB help file, the inconsistency could usefully be highlighted to reduce the likelihood of mistakes.

Richard.

Re: Handle variables in maphandle
Post by k6dgw on Mar 12th, 2018, 9:58pm

Thank you both! It's always the little things that confuse me. smiley