LB Booster
Programming >> Liberty BASIC language >> Data Grid with Specified Column Widths
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1445826111

Data Grid with Specified Column Widths
Post by joker on Oct 26th, 2015, 02:21am

After studying the "data grid" project on the two different forums, I've been working on a version that suits my project.

Thanks to both Richard and RNBW for the work they have done. My ultimate goal is a subroutine.

I decide to add both specified column widths and type of column. My limited Windows experience is now showing, because I'm having a problem.

Garnering data from the previous iterations, I have the column width part working fine.

I have gone beyond my experience level in trying to make the grid have both textboxes and comboboxes within the same grid. I seem to be able to build the grid by my specifications, but I don't seem to have something correct in reading the data from the grid.

Code:
'Last Update: 10/25/2015 9:01:17 PM
' Working on column types: textbox or combobox.

'Last Update: 10/25/2015 8:23:24 PM
' Added variable width columns.
'Last Update: 10/25/2015 5:43:09 PM
' Adding generic variables for rows/cols/width to original code.
'Last Update: 10/25/2015 7:05:24 AM
' Adapted from textbox grid by Richard Russell

numberOfRows = 4
numberOfColumns = 5
leftMargin = 5
rowHeight = 20

dim columnWidth(numberOfColumns) ' contains width for each column
dim columnType(numberOfColumns) ' type of box: 0=textbox, 1=combobox
dim comboArray$(numberOfColumns) ' contains data for combo box (needs REDIM for number of items stored)

columnWidth(1) = 75 : columnType(1) = 1
columnWidth(2) = 55 : columnType(2) = 0
columnWidth(3) = 15 : columnType(3) = 0
columnWidth(4) = 55 : columnType(4) = 0
columnWidth(5) = 35 : columnType(5) = 0

comboArray$(1) = "ONE"
comboArray$(2) = "TWO"
comboArray$(3) = "THREE"
comboArray$(4) = "FOUR"
comboArray$(5) = "FIVE"

cumColumnWidth = 0
for row = 1 to numberOfRows
    for col = 1 to numberOfColumns
        if columnType(col) = 0 then
            textbox #w.tb, leftMargin+cumColumnWidth, row*rowHeight, columnWidth(col), rowHeight
            maphandle #w.tb, "#w.tb";row;col
        else
            ' COMBOBOX #handle.ext, array$(), eventHandler, xPos, yPos, wide, high
            combobox #w.cb, comboArray$(), [validCombo], leftMargin+cumColumnWidth, row*rowHeight, columnWidth(col), rowHeight
            maphandle #w.cb, "#w.cb";row;col
        end if
        cumColumnWidth = cumColumnWidth + columnWidth(col)
    next col
    cumColumnWidth = 0
next row
    
texteditor #w.ted, 10, 150, 200,100  
button #w.btn, "CALC", [Calc], UL, 210,150,60,30

open "Textbox grid" for window as #w
'#w.tb42 "Some text"
wait 

[Calc]
#w.ted "!cls"
for row = 1 to numberOfRows
    for col = 1 to numberOfColumns
        if columnType(col) = 0 then
            h$ = "#w.tb";row;col
        else
            h$ = "#w.cb";row;col
        end if
        'print #handle.ext, "contents? text$"
        #h$ "!contents? b$"
        print #w.ted, row;":";col;" ";b$
    next   
next 
wait

[validCombo]
' dummy
wait                   
 

Re: Data Grid with Specified Column Widths
Post by joker on Oct 26th, 2015, 08:03am

Figured out the problem! Just needed a little sleep ...

LB is not exactly consistent ...

The difference was in the template that I copied right above the line with the problem. The assignment to the string is different for a combobox and a textbox. The "!" is important.

Code:

[Calc]
#w.ted "!cls"
for row = 1 to numberOfRows
    for col = 1 to numberOfColumns
        if columnType(col) = 0 then
            h$ = "#w.tb";row;col
            #h$ "!contents? b$"
        else
            'print #handle.ext, "contents? text$"
            h$ = "#w.cb";row;col
            #h$ "contents? b$"
        end if
        print #w.ted, row;":";col;" ";b$
    next   
next 
wait


 

Re: Data Grid with Specified Column Widths
Post by joker on Oct 26th, 2015, 08:13am

The two boxes don't exactly look good combined on the grid.

Apparently the "style" of the borders are different between combo and text boxes.

Perhaps one needs more space than the other.
Re: Data Grid with Specified Column Widths
Post by joker on Oct 26th, 2015, 08:41am

Developed the code for further column box differences with SELECT CASE statements.

Code:
'Last Update: 10/26/2015 3:35:11 AM
' Developed column types of three. Could be extended. pnlawrence
'Last Update: 10/25/2015 9:01:17 PM
' Working on column types: textbox or combobox. pnlawrence
'Last Update: 10/25/2015 8:23:24 PM
' Added variable width columns. pnlawrence
'Last Update: 10/25/2015 5:43:09 PM
' Adding generic variables for rows/cols/width to original code. pnlawrence
'Last Update: 10/25/2015 7:05:24 AM
' Adapted from textbox grid by Richard Russell

' Seems to be only for LBB because of "maphandle #w.tb, "#w.tb";row;col"

numberOfRows = 4
numberOfColumns = 5
leftMargin = 5
rowHeight = 20

dim columnWidth(numberOfColumns) ' contains width for each column
dim columnType(numberOfColumns) ' type of box: 0=textbox, 1=combobox1, 2=combobox2
dim comboArray$(numberOfColumns) ' contains data for combo box (needs REDIM for number of items stored)

columnWidth(1) = 75 : columnType(1) = 1
columnWidth(2) = 55 : columnType(2) = 0
columnWidth(3) = 15 : columnType(3) = 0
columnWidth(4) = 55 : columnType(4) = 2
columnWidth(5) = 35 : columnType(5) = 0

comboArray$(1) = "ONE"
comboArray$(2) = "TWO"
comboArray$(3) = "THREE"
comboArray$(4) = "FOUR"
comboArray$(5) = "FIVE"

comboArray2$(1) = "AAA"
comboArray2$(2) = "BBB"
comboArray2$(3) = "CCC"
comboArray2$(4) = "DDD"
comboArray2$(5) = "EEE"

cumColumnWidth = 0
for row = 1 to numberOfRows
    for col = 1 to numberOfColumns
        select case columnType(col)
            case 0
                textbox #w.tb, leftMargin+cumColumnWidth, row*rowHeight, columnWidth(col), rowHeight
                maphandle #w.tb, "#w.tb";row;col
            case 1
                ' COMBOBOX #handle.ext, array$(), eventHandler, xPos, yPos, wide, high
                combobox #w.cb, comboArray$(), [validCombo], leftMargin+cumColumnWidth, row*rowHeight, columnWidth(col), rowHeight
                maphandle #w.cb, "#w.cb";row;col
            case 2
                ' COMBOBOX #handle.ext, array$(), eventHandler, xPos, yPos, wide, high
                combobox #w.cbb, comboArray2$(), [validCombo], leftMargin+cumColumnWidth, row*rowHeight, columnWidth(col), rowHeight
                maphandle #w.cbb, "#w.cbb";row;col
        end select
        cumColumnWidth = cumColumnWidth + columnWidth(col)
    next col
    cumColumnWidth = 0
next row
    
texteditor #w.ted, 10, 150, 200,100  
button #w.btn, "CALC", [Calc], UL, 210,150,60,30

open "Textbox grid by Richard Russell" for window as #w
wait 

[Calc]
#w.ted "!cls"
for row = 1 to numberOfRows
    for col = 1 to numberOfColumns
        select case columnType(col)
            case 0
                h$ = "#w.tb";row;col
                #h$ "!contents? b$"
            case 1
                'print #handle.ext, "contents? text$"
                h$ = "#w.cb";row;col
                #h$ "contents? b$"
            case 2
                'print #handle.ext, "contents? text$"
                h$ = "#w.cbb";row;col
                #h$ "contents? b$"
        end select
        print #w.ted, row;":";col;" ";b$
    next   
next 
wait

[validCombo]
' dummy
wait                                     
 

Re: Data Grid with Specified Column Widths
Post by joker on Oct 26th, 2015, 09:13am

Oh, and I finally figured out that
Code:
;row;col 

makes the handle unique in
Code:
maphandle #w.box, "#w.box";row;col 

and changed all the handles to the same ".ext".
Re: Data Grid with Specified Column Widths
Post by RNBW on Oct 26th, 2015, 09:49am

You can change the border to the textboxes by adding

stylebits #w.tb, 0, _WS_BORDER,0,0

immediately after case 0,

This is a bit closer in style, but unfortunately, the border for the textbox is still not the same as for the combobox. I'm not sure if you can get exactly the same border for both.

Ray


Re: Data Grid with Specified Column Widths
Post by joker on Oct 26th, 2015, 10:03am

Thanks, Ray.

I did eventually try that, but it was just as bad (only in a different way!)

I may end up having to add space around each cell.
Re: Data Grid with Specified Column Widths
Post by joker on Oct 26th, 2015, 10:48am

With Ray's addition and added space around the cells.

Curiously, "rowHeight" does not affect the comboBox; only font size affects the height of the comboBox. I don't see any affect of rowHeight on comboBox, but I did not try to change font size. I know what the help says it does, but I didn't see any affect.

Code:
'Last Update: 10/26/2015 5:43:26 AM
' Added space around the cells. pnlawrence

'Last Update: 10/26/2015 4:17:15 AM
' Corrected all the handles to the same "w.cell" pnlawrence

'Last Update: 10/26/2015 3:35:11 AM
' Developed column types of three. Could be extended. pnlawrence
'Last Update: 10/25/2015 9:01:17 PM
' Working on column types: textbox or combobox. pnlawrence
'Last Update: 10/25/2015 8:23:24 PM
' Added variable width columns. pnlawrence
'Last Update: 10/25/2015 5:43:09 PM
' Adding generic variables for rows/cols/width to original code. pnlawrence
'Last Update: 10/25/2015 7:05:24 AM
' Adapted from textbox grid by Richard Russell

' Seems to be only for LBB because of "maphandle #w.cell, "#w.cell";row;col"

numberOfRows = 4
numberOfColumns = 5
leftMargin = 5
cellMargin = 5
rowHeight = 20
cumRowHeight = 0 ' define
cumColumnWidth = 0 ' define

dim columnWidth(numberOfColumns) ' contains width for each column
dim columnType(numberOfColumns) ' type of box: 0=textbox, 1=combobox1, 2=combobox2
dim comboArray$(numberOfColumns) ' contains data for combo box (needs REDIM for number of items stored)

columnWidth(1) = 75 : columnType(1) = 1
columnWidth(2) = 55 : columnType(2) = 0
columnWidth(3) = 15 : columnType(3) = 0
columnWidth(4) = 55 : columnType(4) = 2
columnWidth(5) = 35 : columnType(5) = 0

comboArray$(1) = "ONE"
comboArray$(2) = "TWO"
comboArray$(3) = "THREE"
comboArray$(4) = "FOUR"
comboArray$(5) = "FIVE"

comboArray2$(1) = "AAA"
comboArray2$(2) = "BBB"
comboArray2$(3) = "CCC"
comboArray2$(4) = "DDD"
comboArray2$(5) = "EEE"

cumColumnWidth = 0
cumRowHeight = 0

for row = 1 to numberOfRows
    for col = 1 to numberOfColumns
        select case columnType(col)
            case 0
                stylebits #w.cell, 0, _WS_BORDER,0,0 ' trying to make textbox border look like combobox border
                textbox #w.cell, leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col), rowHeight
                maphandle #w.cell, "#w.cell";row;col
            case 1
                ' COMBOBOX #handle.ext, array$(), eventHandler, xPos, yPos, wide, high
                ' COMBOBOX doesn't recognize rowHeight. Height is determined from font size. rowHeight doesn't seem to have any effect.
                combobox #w.cell, comboArray$(), [validCombo], leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col), rowHeight
                maphandle #w.cell, "#w.cell";row;col
            case 2
                ' COMBOBOX #handle.ext, array$(), eventHandler, xPos, yPos, wide, high
                ' COMBOBOX doesn't recognize rowHeight. Height is determined from font size. rowHeight doesn't seem to have any effect.
                combobox #w.cell, comboArray2$(), [validCombo], leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col), rowHeight
                maphandle #w.cell, "#w.cell";row;col
        end select
        cumColumnWidth = cellMargin + cumColumnWidth + columnWidth(col)
    next col
    cumColumnWidth = 0
    cumRowHeight = cellMargin + cumRowHeight + rowHeight
next row
cumRowHeight = 0
    
texteditor #w.ted, 10, 150, 200,100  
button #w.btn, "CALC", [Calc], UL, 210,150,60,30

open "Textbox grid by Richard Russell" for window as #w
wait 

[Calc]
#w.ted "!cls"
for row = 1 to numberOfRows
    for col = 1 to numberOfColumns
        select case columnType(col)
            case 0
                h$ = "#w.cell";row;col
                #h$ "!contents? b$"
            case 1
                'print #handle.ext, "contents? text$"
                h$ = "#w.cell";row;col
                #h$ "contents? b$"
            case 2
                'print #handle.ext, "contents? text$"
                h$ = "#w.cell";row;col
                #h$ "contents? b$"
        end select
        print #w.ted, row;":";col;" ";b$
    next   
next 
wait

[validCombo]
' dummy
wait                                                                                     
 

Re: Data Grid with Specified Column Widths
Post by Richard Russell on Oct 26th, 2015, 12:09pm

on Oct 26th, 2015, 09:49am, RNBW wrote:
unfortunately, the border for the textbox is still not the same as for the combobox.

Actually on my Windows 10 laptop, running the default theme, the borders do look identical, but the heights are slightly different. Here I can get a good match (with no gaps) as follows:

Code:
stylebits #w.tb, 0, _WS_BORDER, 0, 0
textbox #w.tb, leftMargin+cumColumnWidth, row*rowHeight, columnWidth(col), rowHeight+1 

Note the rowHeight+1.

on Oct 26th, 2015, 10:48am, pnlawrence wrote:
Curiously, "rowHeight" does not affect the comboBox

Whether or not the height value affects the combobox will depend, I think, on whether it's a pre 'Windows XP styles' combobox or a post 'XP styles' combobox (put another way, on what version of the Common Controls library is in use). This is determined by the version of Windows and the contents of the manifest; LBB, and executables compiled by LBB, have a manifest which calls for Common Controls library v6.0.

Richard.
Re: Data Grid with Specified Column Widths
Post by RNBW on Oct 26th, 2015, 3:03pm

Interesting. My laptop is Windows 10 and, using the code without gaps, I got a different border on the textboxes to the comboboxes.

I tried changing the code as Richard suggested in his last post and the horizontal borders were all the same, but the internal vertical borders were all thicker.

However, if you use PNL's code which produces the gaps between the textboxes and comboboxes and use rowHeight+1 for the textbox instead of just rowHeight, it comes out perfectly.

One thing that I don't understand is why the height of comboboxes doesn't change if you change the rowheight.

Ray
Re: Data Grid with Specified Column Widths
Post by RNBW on Oct 26th, 2015, 3:13pm

It's one of those things that you can't see for looking. Richard came up with part of the solution. The rest is to add 1 to the column width for both textboxe and comboboxes. The code below works perfectly for me:

Code:
 
'Last Update: 10/26/2015 5:43:26 AM
' Added space around the cells. pnlawrence

'Last Update: 10/26/2015 4:17:15 AM
' Corrected all the handles to the same "w.cell" pnlawrence

'Last Update: 10/26/2015 3:35:11 AM
' Developed column types of three. Could be extended. pnlawrence
'Last Update: 10/25/2015 9:01:17 PM
' Working on column types: textbox or combobox. pnlawrence
'Last Update: 10/25/2015 8:23:24 PM
' Added variable width columns. pnlawrence
'Last Update: 10/25/2015 5:43:09 PM
' Adding generic variables for rows/cols/width to original code. pnlawrence
'Last Update: 10/25/2015 7:05:24 AM
' Adapted from textbox grid by Richard Russell

' Seems to be only for LBB because of "maphandle #w.cell, "#w.cell";row;col"

numberOfRows = 4
numberOfColumns = 5
leftMargin = 0
cellMargin = 0
rowHeight = 20
cumRowHeight = 0 ' define
cumColumnWidth = 0 ' define

dim columnWidth(numberOfColumns) ' contains width for each column
dim columnType(numberOfColumns) ' type of box: 0=textbox, 1=combobox1, 2=combobox2
dim comboArray$(numberOfColumns) ' contains data for combo box (needs REDIM for number of items stored)

columnWidth(1) = 75 : columnType(1) = 1
columnWidth(2) = 55 : columnType(2) = 0
columnWidth(3) = 15 : columnType(3) = 0
columnWidth(4) = 55 : columnType(4) = 2
columnWidth(5) = 35 : columnType(5) = 0

comboArray$(1) = "ONE"
comboArray$(2) = "TWO"
comboArray$(3) = "THREE"
comboArray$(4) = "FOUR"
comboArray$(5) = "FIVE"

comboArray2$(1) = "AAA"
comboArray2$(2) = "BBB"
comboArray2$(3) = "CCC"
comboArray2$(4) = "DDD"
comboArray2$(5) = "EEE"

cumColumnWidth = 0
cumRowHeight = 0

for row = 1 to numberOfRows
    for col = 1 to numberOfColumns
        select case columnType(col)
            case 0
                stylebits #w.cell, 0, _WS_BORDER, 0, 0
                textbox #w.cell, cumColumnWidth, cumRowHeight, columnWidth(col)+1, rowHeight+1
                maphandle #w.cell, "#w.cell";row;col
            case 1
                ' COMBOBOX #handle.ext, array$(), eventHandler, xPos, yPos, wide, high
                ' COMBOBOX doesn't recognize rowHeight. Height is determined from font size. rowHeight doesn't seem to have any effect.
                combobox #w.cell, comboArray$(), [validCombo], leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col)+1, rowHeight
                maphandle #w.cell, "#w.cell";row;col
            case 2
                ' COMBOBOX #handle.ext, array$(), eventHandler, xPos, yPos, wide, high
                ' COMBOBOX doesn't recognize rowHeight. Height is determined from font size. rowHeight doesn't seem to have any effect.
                combobox #w.cell, comboArray2$(), [validCombo], leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col)+1, rowHeight
                maphandle #w.cell, "#w.cell";row;col
        end select
        cumColumnWidth = cellMargin + cumColumnWidth + columnWidth(col)
    next col
    cumColumnWidth = 0
    cumRowHeight = cellMargin + cumRowHeight + rowHeight
next row
cumRowHeight = 0
    
texteditor #w.ted, 10, 150, 200,100  
button #w.btn, "CALC", [Calc], UL, 210,150,60,30

open "Textbox grid by Richard Russell" for window as #w
wait 

[Calc]
#w.ted "!cls"
for row = 1 to numberOfRows
    for col = 1 to numberOfColumns
        select case columnType(col)
            case 0
                h$ = "#w.cell";row;col
                #h$ "!contents? b$"
            case 1
                'print #handle.ext, "contents? text$"
                h$ = "#w.cell";row;col
                #h$ "contents? b$"
            case 2
                'print #handle.ext, "contents? text$"
                h$ = "#w.cell";row;col
                #h$ "contents? b$"
        end select
        print #w.ted, row;":";col;" ";b$
    next   
next 
wait

[validCombo]
' dummy
wait    
 


Ray
Re: Data Grid with Specified Column Widths
Post by Richard Russell on Oct 26th, 2015, 3:47pm

on Oct 26th, 2015, 3:03pm, RNBW wrote:
One thing that I don't understand is why the height of comboboxes doesn't change if you change the rowheight.

As I said before, it depends on the version of the Common Controls library you are using. The supplied height value has never (to my knowledge) affected the size of the non-dropped-down combobox, but when using Common Controls prior to v6.0 (in other words before 'Windows XP Visual Styles') it did affect the height of the dropped-down box.

This could occasionally be useful because you could set the box to display (say) only four items even if there were more in the list. However it confused a lot of people because if set too small it could result in the box appearing not to drop down properly when you clicked on the arrow.

Post Common Controls v6.0 the size of the dropped-down box is determined only by the number of items in the list, I think, and it may be that the supplied height value now has no effect.

If you really wanted to I expect you could get the handle of the combobox's text-box (the GetComboBoxInfo API function returns that) and then explicitly re-size it using (for example) SetWindowPos.

Richard.

Re: Data Grid with Specified Column Widths
Post by joker on Oct 26th, 2015, 3:53pm

Quote:
If you really wanted to ...


I'm starting to like the way it has turned out more and more. wink wink wink

I am beginning to convert this to a sub ... I think.

Any ideas on that? Suggestions?
Re: Data Grid with Specified Column Widths
Post by RNBW on Oct 26th, 2015, 4:17pm

I presume I am using the common controls prevalent for Windows 10, which I assume is version 6. However, you may be right and the best way to deal with it is to find the hassle of the combobox's text box using an api call. I must start delving into the Windows API. It so often seems to be the way around things with LB.

Ray
Re: Data Grid with Specified Column Widths
Post by RNBW on Oct 26th, 2015, 4:19pm

Sorry about the typo. It should be handle not hassle.
Re: Data Grid with Specified Column Widths
Post by joker on Oct 26th, 2015, 4:25pm

Perhaps you had a little Freudian slip? cheesy

on Oct 26th, 2015, 4:19pm, RNBW wrote:
Sorry about the typo. It should be handle not hassle.

Re: Data Grid with Specified Column Widths
Post by Richard Russell on Oct 26th, 2015, 5:17pm

on Oct 26th, 2015, 4:17pm, RNBW wrote:
I presume I am using the common controls prevalent for Windows 10

I'm not sure whether Windows 10 comes with only Common Controls v6 (or later) or whether an earlier version is supplied as well for compatibility. To find out you would have to modify the LBB manifest (or, more safely, the manifest in a compiled EXE) using a resource editor.

There is some relevant information here:

https://msdn.microsoft.com/en-us/library/windows/desktop/hh298349.aspx

Richard.

Re: Data Grid with Specified Column Widths
Post by joker on Oct 27th, 2015, 01:03am

I've been fighting this for a while now and have given up for the night.

I'm trying to put column headings over the grid. Started out with textboxes, but I can't get the "print" to work to the textbox.

I added the following code right before the part where the grid is drawn. It prints the boxes in a fine manner, but I can't get the text to print.

I must not understand something. Any enlightenment?

Code:
cumColumnWidth = 0
for col = 1 to numberOfColumns
    'stylebits #w.collbl, 0, _WS_BORDER,0,0 ' trying to make textbox border look like combobox border
    textbox #w.collbl, leftMargin+cumColumnWidth, cellMargin+0, columnWidth(col)+1, rowHeight+1
    maphandle #w.collbl, "#w.collbl";col
    h$ = "#w.collbl";col
    ' print #handle.ext, "a string"
    print #h$, columnLabel$(col);
    'print #w.collbl1 "TEST"
    cumColumnWidth = cellMargin + cumColumnWidth + columnWidth(col)
next

 

Re: Data Grid with Specified Column Widths
Post by Richard Russell on Oct 27th, 2015, 09:33am

on Oct 27th, 2015, 01:03am, pnlawrence wrote:
I'm trying to put column headings over the grid. Started out with textboxes, but I can't get the "print" to work to the textbox.

The code you listed appears to be trying to print to a textbox before the textbox even exists (i.e. before the open statement)! You will need two loops, one to define the textboxes before the open, and the other to print to the textboxes after the open.

If you do use textboxes for the column headers remember to make them read-only: you don't want the user to be able to edit them! You will also want to remove the tabstop style from the header boxes, because it isn't helpful to allow the user to tab through them:

Code:
    stylebits #w.collbl, _ES_READONLY, _WS_BORDER or _WS_TABSTOP, 0, 0
 

Possibly centering the heading text in the boxes would be desirable too:

Code:
    stylebits #w.collbl, _ES_READONLY or _ES_CENTER, _WS_BORDER or _WS_TABSTOP, 0, 0
 

You could alternatively use statictext controls for the headers (perhaps with an added border) instead of textboxes, which would avoid some of these complications.

Richard.

Re: Data Grid with Specified Column Widths
Post by RNBW on Oct 27th, 2015, 09:51am

Richard
I downloaded a resource editor and found that LB 4.04 and 4.5 both indicated Common Control 6.0.0 in their Manifests as did your own BB4W.

As far as I can see from MS info, the latest version is 6.1, but the table I got this from shows this for Windows 7. No mention is made of layer Windows versions.

Ray
Re: Data Grid with Specified Column Widths
Post by joker on Oct 27th, 2015, 10:29am

Had to be something to do with ignorance. Now I know something new. Only 5492 lessons left to go!

Guess I'll have to use statictext because putting the grid in a sub is my goal. The window won't normally be open at that point. We'll see, though.

Quote:
You could alternatively use statictext controls for the headers (perhaps with an added border) instead of textboxes, which would avoid some of these complications.

Re: Data Grid with Specified Column Widths
Post by RNBW on Oct 27th, 2015, 10:54am

on Oct 27th, 2015, 10:29am, pnlawrence wrote:
Guess I'll have to use statictext because putting the grid in a sub is my goal. The window won't normally be open at that point. We'll see, though.


It would be part of the set up of the table and the printing of the text in the headings would be after you had opened the window for the rest of the table. so if the problem about it being in a sub applies to the headings it will also apply to the rest of the table.

Richard's advice is good and you just need to set up a loop to construct textboxes for the headings. After opening the window just print the text into the textbox headings.

Richard provided an example of how to do this in the scrolling example at "Re: Variable Number Of Rows Of Texboxes
« Reply #6 on: 04/03/15 at 10:46am »
" in the Liberty Basic Language section.

Ray
Re: Data Grid with Specified Column Widths
Post by tsh73 on Oct 27th, 2015, 11:52am

pnlawrence, "grid in a sub":
- will it be created via sub, and then control passed to main program
- or will it be kind of "modal window" - you call a sub, it shows grid, you vew/change stuff/then close window - (only) then you return from sub?
Just curious.
Re: Data Grid with Specified Column Widths
Post by joker on Oct 27th, 2015, 1:17pm

At this point, the "modal" part is the only reason I'm developing the sub.

However, I do intend to leave out the "modal" part at some point, but for another project.

I can see this working out both ways, but not necessarily together in the same program.

That's why I'm having a few problems with the old adage, "Which came first, the sub or the window?" cheesy

Quote:
- will it be created via sub, and then control passed to main program
- or will it be kind of "modal window" - you call a sub, it shows grid, you vew/change stuff/then close window - (only) then you return from sub?

Re: Data Grid with Specified Column Widths
Post by Richard Russell on Oct 27th, 2015, 3:26pm

on Oct 27th, 2015, 1:17pm, pnlawrence wrote:
That's why I'm having a few problems with the old adage, "Which came first, the sub or the window?"

I wouldn't expect you to have much trouble incorporating your code in a SUB, but bear in mind that in LB/LBB handles are automatically global but handle variables have the same scoping rules as any other variables. Since it is likely that your code will use both, this could be a source of confusion.

Richard.

Re: Data Grid with Specified Column Widths
Post by joker on Oct 28th, 2015, 12:06am

I was anticipating that the results of input to the "modal" grid would be returned (from the sub) in an array set up for that purpose. In that case the grid window would be an entry/edit window and everything should be contained within and the scope of variables should be local to the sub.

In the case where the code is not "modal" in operation, but is the main user input screen, I would anticipate the "cells" of the grid would be read with locally scoped variables.

Do I understand that correctly? It is all new to me.

I am not sure of the handles that are produced by MAPHANDLE or the handles that those handles are "mapped" from --- the original handles. Does the original handle just go away after using MAPHANDLE?
Re: Data Grid with Specified Column Widths
Post by Richard Russell on Oct 28th, 2015, 12:54pm

on Oct 28th, 2015, 12:06am, pnlawrence wrote:
I was anticipating that the results of input to the "modal" grid would be returned (from the sub) in an array set up for that purpose.

In LB all arrays are global; it's a significant limitation but may actually make things easier for you.

Quote:
Does the original handle just go away after using MAPHANDLE?

Yes, effectively it ceases to exist after using MAPHANDLE.

Richard.

Re: Data Grid with Specified Column Widths
Post by joker on Oct 31st, 2015, 11:57am

Here is what I am working on/with for now. I probably won't do much more generically for posting, but will probably start running with my own version of my own version! :o

The demo code is in the next post. Just put them together. It is kind of clunky (ok, really clunky), but I'm sure y'all can keep up! ;)

EDIT: Corrected single digit handle index for the grid "boxes" with a two digit zero padded left handle index.

Code:
sub gridSetup topMargin, numberOfRows, numberOfColumns, leftMargin, cellMargin, rowHeight, labelFormat
' Place a grid window of text and combo boxes for user input
' Uses window handle:  #gridWnd
' Tremendous thanks to Richard Russell and Ray(RNBW) on the LBB forum for contributing the most.
' Last Update: 11/02/2015 6:33:00 PM - pnlawrence
'
' =================================================================================================
'   Parameters required:
'       topMargin - indent below column headers/labels
'       numberOfRows
'       numberOfColumns
'       leftMargin - an indent for the grid left side
'       cellMargin - space around the cells of the grid (not left side)
'       rowHeight - boxes use this. Depends on windows font size.
'       labelFormat - bit-based format byte:
'           BIT VAL FORMAT CHARACTERISTIC (lower number bits take precedence on conflict
'            0   1  no column label; no top margin (default is UPPERCASE, no border)
'            1   2  no column label; create top margin
'            2   4  column label in LOWERCASE
'            3   8  column label in PROPERCASE (not implemented)
'            4  16  column label with border
'            5
'            6
'            7
'
'   Arrays necessary with data loaded (1-based):
'       columnWidth(numberOfColumns) ' contains width data for each column
'       columnType(numberOfColumns) ' type of box for each column: 0=textbox, 1=combobox1, 2=combobox2
'       columnLabel$(numberOfColumns) ' contains label text for column header/label (see labelFormat for text case)
'       comboArray1$(10) ' contains data for combo box 1 (needs REDIM for number of items stored)
'       comboArray2$(10) ' contains data for combo box 2 (needs REDIM for number of items stored)
' =================================================================================================

' set the label format variables
NOLABEL = (labelFormat AND 1) OR (labelFormat AND 2)
NOTOPMARGIN = labelFormat AND 1
LOWCASELABEL = labelFormat AND 4
PROPERCASELABEL = labelFormat AND 8 ' not implemented as of 10/28/2015
LABELBORDER = labelFormat AND 16 ' add a border

' create the column labels per the labelFormat
if NOLABEL = 0 then ' create label
    cumColumnWidth = 0
    for col = 1 to numberOfColumns
        if LOWCASELABEL then ' label lower case
            statictext #gridWnd.collbl, lower$(columnLabel$(col)),leftMargin+cumColumnWidth, cellMargin, columnWidth(col)+1, rowHeight-2
        else ' label uppper case
            statictext #gridWnd.collbl, upper$(columnLabel$(col)),leftMargin+cumColumnWidth, cellMargin, columnWidth(col)+1, rowHeight-2
        end if
        if LABELBORDER then ' create border
            stylebits #gridWnd.collbl,_SS_CENTER or _WS_BORDER,0,0,0
        else ' no border
            stylebits #gridWnd.collbl,_SS_CENTER,_WS_BORDER,0,0
        end if
        cumColumnWidth = cumColumnWidth + columnWidth(col) + 1 + cellMargin
    next
end if

' start with first row/column
cumColumnWidth = 0
if NOTOPMARGIN then
    cumRowHeight = 0
else
    cumRowHeight = topMargin ' leaves room for column headers
end if

for row = 1 to numberOfRows
    for col = 1 to numberOfColumns
        select case columnType(col)
            case 0
                stylebits #gridWnd.cell, 0, _WS_BORDER,0,0 ' trying to make textbox border look like combobox border
                textbox #gridWnd.cell, leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col)+1, rowHeight+1
                rc$=right$("00"+str$(row),2)+right$("00"+str$(col),2)
                maphandle #gridWnd.cell, "#gridWnd.cell"+rc$ ';row;col
            case 1
                ' COMBOBOX doesn't recognize rowHeight. Height is determined from font size. rowHeight doesn't seem to have any effect.
                combobox #gridWnd.cell, comboArray1$(), [selectionGridCombo1], leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col)+1, rowHeight
                rc$=right$("00"+str$(row),2)+right$("00"+str$(col),2)
                maphandle #gridWnd.cell, "#gridWnd.cell"+rc$ ';row;col
            case 2
                ' COMBOBOX doesn't recognize rowHeight. Height is determined from font size. rowHeight doesn't seem to have any effect.
                combobox #gridWnd.cell, comboArray2$(), [selectionGridCombo2], leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col)+1, rowHeight
                rc$=right$("00"+str$(row),2)+right$("00"+str$(col),2)
                maphandle #gridWnd.cell, "#gridWnd.cell"+rc$ ';row;col
        end select
        cumColumnWidth = cellMargin + cumColumnWidth + columnWidth(col) + 1
    next col
    cumColumnWidth = 0
    cumRowHeight = cellMargin + cumRowHeight + rowHeight + 1
next row

end sub
 

Re: Data Grid with Specified Column Widths
Post by joker on Oct 31st, 2015, 11:59am

Demo code for the Data Grid subroutine in the previous post.
Code:
'Last Update: 10/31/2015 6:29:34 AM
' Demo is clunky, but provides a platform. pnlawrence

'Last Update: 10/30/2015 5:31:45 AM
' Completed demo of grid subroutine with formatted columns. pnlawrence
'Last Update: 10/30/2015 3:48:16 AM
' Column label positions & widths. pnlawrence
'Last Update: 10/29/2015 8:43:09 PM
' Added window size relative to numRows & numCols & column labels. pnlawrence
'Last Update: 10/28/2015 8:37:41 PM
' Added labelFormat. pnlawrence
'Last Update: 10/28/2015 5:31:47 AM
' Adding the labelFormat byte to use instead of other ways. pnlawrence
'Last Update: 10/27/2015 6:38:34 AM
' Fixed column header code. pnlawrence
'Last Update: 10/26/2015 8:04:22 PM
' Working on column heading labels. pnlawrence
'Last Update: 10/26/2015 5:22:52 PM
' Adding a column label row in gridSetup. pnlawrence
'Last Update: 10/26/2015 11:46:38 AM
' Added window controls. pnlawrence
'Last Update: 10/26/2015 11:21:25 AM
' Added grid drawing subroutine. pnlawrence

' Place a grid window of text and combo boxes for user input. The grid is "modal".
' Tremendous thanks to Richard Russell and Ray(RNBW) on the LBB forum for contributing the most.
'
' Begin with the main window
Nomainwin

gosub [MAINWINSETUP]

gosub [GRIDVARIABLESSETUP]

gosub [GRIDWINDOWSETUP]

gosub [GRIDCONTROLSETUP]

gosub [GRIDSETUP]

'===================================

[MAINLOOP]
wait 

'===================================

[selectionGridCombo1]
' dummy
wait

[selectionGridCombo2]
' dummy
wait

[PRINTGRID]
[SAVEGRID]
[EDITPERSON]
[QUITGRID]
    close #gridWnd
    wait

[PERSON]
[QUIT]
    close #gridWnd
    close #mainWnd
    END

[GRIDWINDOWSETUP]
    ' Determine the width of the window
    WindowWidth = leftMargin ' passing value for cumulative column width
    for col = 1 to numberOfColumns
        WindowWidth =  WindowWidth + columnWidth(col) + 1 + cellMargin
    next
    WindowWidth = WindowWidth + cellMargin*5 + cellMargin ' add right margin
    
    ' Determine the height of the window
    if (labelFormat AND 1) OR (labelFormat AND 2) then ' no label row
        WindowHeight = 60 ' start with room for caption and menu bar
    else
        WindowHeight = topMargin + 60 ' start with room for caption & menu bar & top margin
    end if
    for row = 1 to numberOfRows
        WindowHeight = cellMargin + WindowHeight + rowHeight + 1
    next
    WindowHeight = WindowHeight + cellMargin
    
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    LowerRightX=UpperLeftX+WindowWidth
    LowerRightY=UpperLeftY+WindowHeight
    'print "WindowWidth (";WindowWidth;")"
    'print "WindowHeight (";WindowHeight;")"
    'print "Upper(";UpperLeftX;",";UpperLeftY;")"
    'print "Lower(";LowerRightX;",";LowerRightY;")"
    'print "Button (";LowerRightX-200;",";LowerRightY-200;")
return

[GRIDCONTROLSETUP]
    Menu        #gridWnd, "File", "Save GRID", [SAVEGRID], "Quit", [QUITGRID]
    Menu        #gridWnd, "Person", "Edit / Add", [EDITPERSON]
    Menu        #gridWnd, "Report", "Print GRID", [PRINTGRID]
return

[GRIDSETUP] ' create the grid
    call gridSetup topMargin, numberOfRows, numberOfColumns, leftMargin, cellMargin, rowHeight, labelFormat
    Stylebits #gridWnd, 0,_WS_MAXIMIZEBOX,0,0
    open "DATA INPUT GRID" for window as #gridWnd
    #gridWnd "trapclose [QUITGRID]"
    #gridWnd "font ms_sans_serif 10"
    ' set up the column headings if necessary
return

[OUTPUT]
    #mainWnd.ted "!cls"
    for row = 1 to numberOfRows
        for col = 1 to numberOfColumns
            select case columnType(col)
                case 0
                    h$ = "#gridWnd.cell";row;col
                    #h$ "!contents? b$"
                case 1
                    h$ = "#gridWnd.cell";row;col
                    #h$ "contents? b$"
                case 2
                    h$ = "#gridWnd.cell";row;col
                    #h$ "contents? b$"
            end select
            ' printing and/or saving the cell is done here
            print #mainWnd.ted, row;":";col;" ";b$
        next   
    next 
    wait

[GRIDVARIABLESSETUP]
    ' =================================================================================================
    '   Parameters required:
    '       topMargin - indent below column headers
    '       numberOfRows
    '       numberOfColumns
    '       leftMargin - an indent for the grid
    '       cellMargin - space around the cells of the grid
    '       rowHeight - text boxes use this. Depends on font size.
    '       labelFormat - bit-based format byte:
    '           BIT VAL FORMAT CHARACTERISTIC (lower number bits take precedence on conflict
    '            0   1  no column label; no top margin
    '            1   2  no column label; create top margin
    '            2   4  column label in LOWERCASE (default is UPPERCASE)
    '            3   8  column label in PROPERCASE (default is UPPERCASE)
    '            4  16  column label with border (default is no border)
    '            5
    '            6
    '            7
    '
    '   Arrays with data loaded to be made available (1-based):
    '       columnWidth(numberOfColumns) ' contains width for each column
    '       columnType(numberOfColumns) ' type of box: 0=textbox, 1=combobox1, 2=combobox2
    '       columnLabel$(numberOfColumns) ' contains labels for column header
    '       comboArray1$(10) ' contains data for combo box 1 (needs REDIM for number of items stored)
    '       comboArray2$(10) ' contains data for combo box 2 (needs REDIM for number of items stored)
    '       dataArray$(10) ' contains data returned from the grid cells. Will be REDIM to fit the grid.
    ' =================================================================================================
    
    labelFormat = 0
    topMargin = 25
    numberOfRows = 20
    numberOfColumns = 10
    leftMargin = 5
    cellMargin = 3
    rowHeight = 25
    
    dim columnWidth(10) ' contains width for each column
    dim columnType(10) ' type of box: 0=textbox, 1=combobox1, 2=combobox2
    dim columnLabel$(10) ' contains the text labels above the columns
    dim comboArray1$(10) ' contains data for combo box (needs REDIM for number of items stored)
    dim comboArray2$(10) ' contains data for combo box (needs REDIM for number of items stored)
    
    columnWidth(1) = 100    : columnType(1) = 1     : columnLabel$(1) = "One"
    columnWidth(2) = 100    : columnType(2) = 1     : columnLabel$(2) = "Two"
    columnWidth(3) = 50     : columnType(3) = 0     : columnLabel$(3) = "Three"
    columnWidth(4) = 50     : columnType(4) = 0     : columnLabel$(4) = "Four"
    columnWidth(5) = 30    : columnType(5) = 0     : columnLabel$(5) = "Five"
    columnWidth(6) = 50    : columnType(5) = 0     : columnLabel$(6) = "Six"
    columnWidth(7) = 50    : columnType(5) = 0     : columnLabel$(7) = "Seven"
    columnWidth(8) = 20    : columnType(5) = 0     : columnLabel$(8) = "8"
    columnWidth(9) = 50    : columnType(5) = 0     : columnLabel$(9) = "Nine"
    columnWidth(10) = 50    : columnType(5) = 0     : columnLabel$(10) = "Ten"
    ' 550
    
    comboArray1$(1) = "1"
    comboArray1$(2) = "22"
    comboArray1$(3) = "333"
    comboArray1$(4) = "FOUR"
    comboArray1$(5) = "FIVEX"
    comboArray1$(6) = "666666"
    comboArray1$(7) = "7777777"
    comboArray1$(8) = "88888888"
    comboArray1$(9) = "999999999"
    comboArray1$(10) = "12345678901234567890123456789012345678901234567890"
    
    comboArray2$(1) = "AAA"
    comboArray2$(2) = "BBB"
    comboArray2$(3) = "CCC"
    comboArray2$(4) = "DDD"
    comboArray2$(5) = "EEE"
return

[MAINWINSETUP]
    WindowWidth = DisplayWidth - 200
    WindowHeight = DisplayHeight - 100
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    Stylebits   #mainWnd, 0,_WS_MAXIMIZEBOX,0,0
    texteditor  #mainWnd.ted, UpperLeftX+50, UpperLeftY+50, 200, 300  
    button      #mainWnd.btn, " OUTPUT ", [OUTPUT], LR, 170,10
    button      #mainWnd.btn, " PERSON ", [PERSON], LR, 70, 10
    open "MAIN WINDOW" for window as #mainWnd
    #mainWnd "trapclose [QUIT]"
    #mainWnd "font ms_sans_serif 10"
return
 

Re: Data Grid with Specified Column Widths
Post by joker on Nov 1st, 2015, 10:15am

Ran across this comment in the LB help file:

Quote:
NOTE: Branch labels inside functions and subroutines are not visible to code outside those functions and subroutines. If code in the main program tries to access a branch label inside a function or subroutine, this will cause an error. Likewise, functions and subroutines cannot use branch labels defined outside their scope.


The above sub references branch routines outside the sub in the combobox "validation" branches. I don't get any kind of compiler message or error message during execution about this.

Actually, it works just fine from the combobox branch labels.

So, that comment in the LB help file must only refer to program branches within subs.
Re: Data Grid with Specified Column Widths
Post by Richard Russell on Nov 1st, 2015, 12:55pm

on Nov 1st, 2015, 10:15am, pnlawrence wrote:
The above sub references branch routines outside the sub in the combobox "validation" branches. I don't get any kind of compiler message or error message during execution about this.

I think there may be some confusion about what is meant by a 'subroutine'. There are two kinds of subroutine available in Liberty BASIC: there's the old-fashioned kind accessed using GOSUB and there's the modern kind accessed using CALL.

When you see references to 'functions and subs' you can usually assume that it means the modern kind. You must not attempt to jump from 'inside' to 'outside' a FUNCTION or SUB. Even if you do not receive a warning or error message (see earlier threads explaining why LBB's error reporting is sometimes poor) the program will almost certainly crash.

The old-fashioned 'legacy' kind of GOSUB...RETURN subroutine is a completely different animal. Variables, labels, DATA statements etc. are not 'local' to the subroutine like they are with a SUB. You should still avoid jumping out however, because that causes a memory leak (in the same way as jumping out of a loop does), but neither LB nor LBB will actually stop you.

I would argue that GOSUB should probably not be used in a program written today. It is present in Liberty BASIC primarily for compatibility with 'traditional' BASIC programs (rather as line numbers are still supported by LB, but you would never use them in a new program).

For that matter I would argue that you shouldn't use GOTO in a modern program either, but I know that many people disagree, and I definitely don't want to provoke an outbreak of GOTO Wars on this forum. grin

Richard.

Re: Data Grid with Specified Column Widths
Post by joker on Nov 1st, 2015, 2:07pm

Ok, for me there is no confusion about the difference between subs and gosubs, but thanks for saying that anyway.

Then, referring to my previous grid sub, I should include the branch statements within the sub even though it "seems" to work in the demo, because it will eventually break.

[EDIT] Thinking about it makes me wonder how to put a branch from a combobox between the sub/end sub. My sub is just drawing the grid. The actual combobox is out in the main window so the call to the combobox handler is in the main window. The way I have it should work fine.

That is good info. With all the comments everywhere about bugs that everyone is used to and just lives with, its hard not to question some of the documentation. In this case, the doc was absolutely correct.
Re: Data Grid with Specified Column Widths
Post by Richard Russell on Nov 1st, 2015, 3:29pm

on Nov 1st, 2015, 2:07pm, pnlawrence wrote:
Then, referring to my previous grid sub, I should include the branch statements within the sub even though it "seems" to work in the demo, because it will eventually break.

The only labels which are "referenced" inside your SUB are the event handlers for the GUI controls. You are not 'jumping' to those labels from inside the SUB, you are simply 'registering' them with the GUI controls so they know what to do if (e.g.) you click on them.

Maybe you are taking the LB docs rather too literally, in the sense that they imply that the branch labels are 'invisible' inside the SUB. That doesn't mean that the name of the branch label is invisible, only that its location is.

So if you were to try to jump to that label from inside the SUB then it would fail, because it wouldn't know where to jump to. But if you simply pass the name of the label as the event handler to, say, a COMBOBOX command it doesn't need to know its location until the event actually happens.

There would only be a problem if you put the OPEN statement inside the SUB. Then it would be possible for the GUI event to occur before the END SUB, whilst its event handler is out of scope. I suppose there's a theoretical risk of that happening even if the OPEN is the last statement in the SUB.

You are not doing that, so it's not an issue, but if you were then the solution is to use SUB event handlers rather than branch event handlers (SUBs are 'in scope' permanently):

Code:
  combobox #gridWnd.cell, comboArray1$(), selectionGridCombo1, leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col)+1, rowHeight
 

Now the combobox will CALL selectionGridCombo1(handle$) rather than GOTO [selectionGridCombo1] and it won't matter if it happens whilst still inside your SUB or not.

A general advantage of SUB event handlers is that you can safely put a WAIT or a SCAN inside any SUB or FUNCTION without being concerned that, when an event occurs, its handler will be out of scope.

It's for this reason that the TIMER bug in LB 4 is so serious. Despite what the docs say, you cannot use a SUB handler with TIMER so scope issues can be a major problem. In LBB all event handlers can be SUBs and that way scope issues are largely irrelevant.

Richard.

Re: Data Grid with Specified Column Widths
Post by joker on Nov 1st, 2015, 4:41pm

Very clear, Richard. Thanks!
Re: Data Grid with Specified Column Widths
Post by joker on Nov 2nd, 2015, 6:24pm

I'm finding it very klunky saving data out of the grid "boxes" if there's more than a few columns.

Let me clarify, "saving data." I'm saving each row of the grid as a record in a random access file. In one case, I have 20 columns with multiple combo and text boxes.

I was originally wanting to make use of the "handle;row;col" format, but what I try gets tied up with the type of box to be read from. Then there is still the, basically manual, way of mapping to the file field variables.

A magic wand to change the data into field variables is really what I would like to see. Since I'm wishing, it would be nice to allow field variables to be array variables.

EDIT: What I am doing now is transferring data from the grid to an array and resolving any data issues in the process. Then I transfer the array to the records of the RAF since there are only string values to transfer by then. However, it is still klunky.
Re: Data Grid with Specified Column Widths
Post by joker on Nov 2nd, 2015, 7:10pm

Single digit row and columns. I read it in another post, but I've never thought there to be a problem.
http://lbb.conforums.com/index.cgi?board=extensions&action=display&num=1427217832

I never put any limits on the grid's number of rows or columns so the maphandle function that creates a new "box" handle is certainly using more than a single digit for the row and column part.

I've never seen any problem with doing that, but then I read the above post.
Re: Data Grid with Specified Column Widths
Post by Richard Russell on Nov 2nd, 2015, 7:53pm

on Nov 2nd, 2015, 6:24pm, pnlawrence wrote:
what I try gets tied up with the type of box to be read from.

Are you referring to the need to use !CONTENTS? var$ for the text boxes and SELECTION? var$ for the comboboxes? In that case you could create a 2D string array, indexed by row and column, containing the correct command for each control. Most conveniently you could store the command in the array when you originally declare the controls:

Code:
            case 0
                stylebits #gridWnd.cell, 0, _WS_BORDER,0,0 ' trying to make textbox border look like combobox border
                textbox #gridWnd.cell, leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col)+1, rowHeight+1
                maphandle #gridWnd.cell, "#gridWnd.cell";row;col
                Command$(row,col) = "!CONTENTS? "
            case 1
                ' COMBOBOX doesn't recognize rowHeight. Height is determined from font size. rowHeight doesn't seem to have any effect.
                combobox #gridWnd.cell, comboArray1$(), [selectionGridCombo1], leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col)+1, rowHeight
                maphandle #gridWnd.cell, "#gridWnd.cell";row;col
                Command$(row,col) = "SELECTION? "
 


Then, when you want to read the contents back, you simply need to do:

Code:
    for row = 1 to numberOfRows
      for col = 1 to numberOfColumns
        handle$ = "#gridWnd.cell";row;col
        #handle$ Command$(row,col);"var$"
        ' do something with var$
      next col
    next row 

Or have I, once again, misunderstood?

Quote:
Since I'm wishing, it would be nice to allow field variables to be array variables.

It would be fairly easy to support that, I will add it to the wish list. In fact I think you can successfully use numeric array variables in LBB now, but not string array variables.

Richard.
Re: Data Grid with Specified Column Widths
Post by Richard Russell on Nov 2nd, 2015, 8:59pm

on Nov 2nd, 2015, 7:10pm, pnlawrence wrote:
I've never seen any problem with doing that, but then I read the above post.

The problem arises in a situation such as the following. Suppose the row number is 1 and the column number is 10; if you simply concatenate them you would get a handle like #w.box110. Now suppose the row number is 11 and the column number is zero; what handle do you get? It's #w.box110 again!

Of course that doesn't mean you can't use more than 10 rows or columns, but it does mean you have to be more careful with the way you construct the handle variables, for example you could ensure that both row and column are always two-digit numbers. Then the first example would be #w.box0110 and the second example would be #w.box1100.

It may be that in your particular case a conflict never arises, but it might if you enlarged your grid.

Richard.
Re: Data Grid with Specified Column Widths
Post by joker on Nov 2nd, 2015, 9:15pm

Quote:
for example you could ensure that both row and column are always two-digit numbers.


Got it! Don't know why I didn't think that through. (Guess I'm on the Richard Russell BASIC Welfare Program! smiley )
Re: Data Grid with Specified Column Widths
Post by joker on Nov 2nd, 2015, 9:28pm

Quote:
Or have I, once again, misunderstood?


You have "stood" it just right. wink I didn't imagine to store the command in the array, too. That would simplify one part of the FOR/NEXT loop, but I'm not sure that is overall more simple, though.

That's one of those "six one way; half a dozen the other way" situations. Food for thought. Thanks!

On using arrays as RAF field variables, I haven't thought out exactly how that would make it better for me, but thinking there's an advantage in my case. I'm going from GRID -> ARRAY -> FIELD now. It just seems that if the array was the field, then there would be some savings.

I have to constantly remind myself that I am a NOVICE PROGRAMMER with LBB and LB.