LB Booster
« Data Grid with Specified Column Widths »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:59am



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 3361 times)
joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

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

 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Data Grid with Specified Column Widths
« Reply #18 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.
« Last Edit: Oct 27th, 2015, 09:39am by Richard Russell » User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

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

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

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

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: Data Grid with Specified Column Widths
« Reply #22 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.
« Last Edit: Oct 27th, 2015, 11:53am by tsh73 » 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 #23 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?
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


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

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