LB Booster
Programming >> Liberty BASIC language >> Variables in MAINWIN statement http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1502297409 Variables in MAINWIN statement
Post by Richard Russell on Aug 9th, 2017, 4:50pm
I've been looking into the possibility of supporting the MAINWIN statement in LBB console programs (to set the window size), and fortunately it seems fairly straightforward. But on the way I've discovered something strange. If I run this code in LB (4.5.1, but I don't think it matters) it works as expected:
Code:
mainwin 60 30
but if I run this code it doesn't work:
Code:
cols = 60
rows = 30
mainwin cols rows
Am I doing something stupid? Surely it must be possible to set the mainwin size to values determined at run-time? Nothing in the Liberty BASIC Docs appears to suggest otherwise, and no errors or warnings are reported either at compile or run time, but it doesn't seem to work.
Richard.
Re: Variables in MAINWIN statement
Post by BrianM on Aug 9th, 2017, 7:36pm
Richard
MAINWIN is not an executable statement but a tokeniser directive. During the creation of a token file the basic is scanned for MAINWIN statements and the the values for rows and columns are stored in the token file. If variables are used then values of zero are used. Zero values give a maximised window. If more than one MAINWIN statement exists in a basic file then the last one is used.
Brian Matthews
Re: Variables in MAINWIN statement
Post by Richard Russell on Aug 9th, 2017, 8:26pm
MAINWIN is not an executable statement but a tokeniser directive.
How very strange; is that formally documented anywhere? I can't see anything in the main LB Help file that even hints at it: MAINWIN is described just like any other statement (unlike NOMAINWIN which is listed as a 'directive').
Needless to say in LBB it works 'sensibly': you can specify the dimensions with variables and you change the size of the mainwin whenever you wish as the program runs. I suppose I should add this to the list of enhancements.
Even when you think you can't be surprised by LB 4 any more, something else pops out of the woodwork!
Richard. Re: Variables in MAINWIN statement
Post by BrianM on Aug 9th, 2017, 8:41pm
Richard
The only hint that MAINWIN is a directive is in the help -
"This statement is usually placed at the beginning of the program code."
In LB the size of the main window is fixed when the program is tokenised. The advantage of LBB is that the size can be dynamically changed during execution.
Brian
Re: Variables in MAINWIN statement
Post by Richard Russell on Aug 9th, 2017, 9:11pm
"This statement is usually placed at the beginning of the program code."
Well, to me that hints at the opposite! If it makes no difference where the MAINWIN statement goes, why recommend that it goes at the beginning? In the case of LBB, however, it does matter that it goes near the beginning, to ensure the wanted size is established as quickly as possible.
Hence the documentation would lead me to expect the LBB behaviour, and in well over five years I've never had any reason to doubt it. Only in experimenting with MAINWIN in a console program did I notice anything unexpected.