LB Booster
« Data Grid with Specified Column Widths »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 05:21am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1 2 3  Notify Send Topic Print
 veryhotthread  Author  Topic: Data Grid with Specified Column Widths  (Read 3377 times)
joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: Data Grid with Specified Column Widths
« Reply #25 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?
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Data Grid with Specified Column Widths
« Reply #26 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.
User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: Data Grid with Specified Column Widths
« Reply #27 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
 
« Last Edit: Nov 2nd, 2015, 11:35pm by joker » User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: Data Grid with Specified Column Widths
« Reply #28 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
 
User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: Data Grid with Specified Column Widths
« Reply #29 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.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Data Grid with Specified Column Widths
« Reply #30 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.
« Last Edit: Nov 1st, 2015, 12:56pm by Richard Russell » User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: Data Grid with Specified Column Widths
« Reply #31 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.
« Last Edit: Nov 1st, 2015, 2:37pm by joker » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Data Grid with Specified Column Widths
« Reply #32 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.
User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: Data Grid with Specified Column Widths
« Reply #33 on: Nov 1st, 2015, 4:41pm »

Very clear, Richard. Thanks!
User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: Data Grid with Specified Column Widths
« Reply #34 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.
« Last Edit: Nov 2nd, 2015, 7:34pm by joker » User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: Data Grid with Specified Column Widths
« Reply #35 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.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Data Grid with Specified Column Widths
« Reply #36 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.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Data Grid with Specified Column Widths
« Reply #37 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.
« Last Edit: Nov 2nd, 2015, 9:15pm by Richard Russell » User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: Data Grid with Specified Column Widths
« Reply #38 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 )
User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: Data Grid with Specified Column Widths
« Reply #39 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.
User IP Logged

Pages: 1 2 3  Notify Send Topic Print
« Previous Topic | Next Topic »


This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls