LB Booster
Programming >> Language extensions >> STRINGWIDTH?
http://lbb.conforums.com/index.cgi?board=extensions&action=display&num=1428968280

STRINGWIDTH?
Post by Dacite on Apr 13th, 2015, 11:38pm

Oops - My bad... Works great!

Stringwidth? sounded like the neatest thing since the Large Hadron Collider, but I get X = 0 when I use it.
Code:
GRAPHICBOX #g.gb 5, 5, 100, 100
TEXTEDITOR #g.te 115, 5, 100, 200
open "Init" for Window as #g
#g.gb "trapclose [Done]"
#g.gb "font lucida_console 12"
#g.gb "backcolor green"
#g.gb "color yellow"
#g.gb "place 0 0"
#g.gb "\"  ''' Write a line feed
#g.gb "posxy X Y"  ''' Get graphics cursor position (font height)

Char$ = "X"
#g.te "!STRINGWIDTH? ";Char$;" "; X
print X, Y  '* Prints 0  20 *

#g.te "!STRINGWIDTH? Char$ X"
print X, Y  '* Prints 0  20 *

#g.gb "\"; Char$  '* Write a char *

wait

[Done]
CLOSE #g
END 

Is the code I'm using. I also tried a literal "X", all variables inside the quotes, forum search for STRINGWIDTH?, restarting LBB... Without specifying the texteditor all I got was the "Mistake" box. Without the ! it prints STRINGWIDTH?.
Re: STRINGWIDTH? not working
Post by RobM on Apr 14th, 2015, 02:59am

STRINGWIDTH is a graphics command. It isn't intended to work with texteditors.

Code:
GRAPHICBOX #g.gb 5, 5, 100, 100
TEXTEDITOR #g.te 115, 5, 100, 200
open "Init" for Window as #g
#g.gb "trapclose [Done]"
#g.gb "font lucida_console 12"
#g.gb "backcolor green"
#g.gb "color yellow"
#g.gb "place 0 0"
#g.gb "\"  ''' Write a line feed
#g.gb "posxy X Y"  ''' Get graphics cursor position (font height)

Char$ = "X"
#g.gb "STRINGWIDTH? ";Char$;" X"
print X, Y  '* Prints 0  20 *

#g.gb "STRINGWIDTH? Char$ X"
print X, Y  '* Prints 0  20 *

#g.gb "\"; Char$  '* Write a char *

wait

[Done]
CLOSE #g
END
 

Re: STRINGWIDTH? not working
Post by Dacite on Apr 14th, 2015, 04:44am

Thank you. For anyone else looking for a solution, here is the correct syntax:
Code:
#g.gb "STRINGWIDTH? Char$ X" 

I will have to test it, but I am assuming that the font width is the same in other display controls...