ADDRESS MANAGER

You can talk about anything related to LB Booster here, not covered in another category
RNBW
Posts: 68
Joined: Thu Apr 05, 2018 9:21 pm

Re: ADDRESS MANAGER

Post by RNBW »

Richard
Thank you for your response. It sounds as though I won't have any problems in respect of space in the textbox, so I'll carry on until a problem arises.
Ray
RNBW
Posts: 68
Joined: Thu Apr 05, 2018 9:21 pm

Re: ADDRESS MANAGER

Post by RNBW »

Richard
Under this series of posts we discussed the position of Stylebits relative to an associated textbox; whether it should come before or after the textbox. At the time I tried out alternative positions, but it didn't seem to matter. You said that logically it should come after the textbox (and I agree with this) but the LB documentation appears to show it coming before the textbox.

I thought the code I had produced for the Address Book was a bit clumsy, so I thought I would try to write it specifically for LBB and lo and behold, the position of Stylebits is important and MUST come after the related textbox otherwise it relates to the texbox preceding it. This can be seen in the code below. If it is positioned after the Notes textbox it correctly refers to the Notes texbox and shows scrollbars. If it is positioned before the Notes textbox, it appears to refer to the preceding E-Mail 2 textbox and puts scrollbars in it and not in the Notes textbox.

Another little quirk in LB!

Code: Select all

nomainwin

    WindowWidth = 830
    WindowHeight = 610
    UpperLeftX = 20
    UpperLeftY = 20
    
    '------------------------------------------------------------------
     'Set up the Textboxes
     ' NOTE that Stylebits must follow the Textbox statements!
     '-----------------------------------------------------------------
    TextboxColor$ = "white"
    print: print
    hPos = 150: bWidth = 300:  bHt = 20: Row = 10
    bWidth2 = 130: bWidth3 = 110
    For i = 1 to Row
       Select Case i
          case 1, 2, 3, 4, 5, 6, 7, 8, 9
           TextBox #main.tb, hPos, (bHt)*i, bWidth+1, bHt+1
           Stylebits #main.tb, _ES_LEFT, _WS_BORDER, 0, 0
           TB$(i) = "#main.tb"; "_r";i      
         case 10
           ' If you remove the Remarks quote on the Stylebits statement below and remark out the Stylebits statement
           ' after the textbox, you will see the scrollbars are placed in the E-Mail 2 textbox instead of the Notes textbox.
           'Stylebits #main.tb, _ES_LEFT OR _WS_VSCROLL OR _ES_MULTILINE, _WS_BORDER OR _ES_AUTOHSCROLL, 0, 0
           TextBox #main.tb, 500, 50, 300, 480
           Stylebits #main.tb, _ES_LEFT OR _WS_VSCROLL OR _ES_MULTILINE, _WS_BORDER OR _ES_AUTOHSCROLL, 0, 0
           maphandle #main.tb, TB$(i)
       end select 
   next
   
       ' Labels
    statictext  #main, " Name/Company:",       20, 22, 110, 20
    statictext  #main, "Tel:",       20, 42, 45, 20
    statictext  #main, "Mob:",        20, 62, 35, 20
    statictext  #main, "Address:",    20, 82, 100, 20
    statictext  #main, "City:",    20, 102, 45, 20
    statictext  #main, "County:",          20, 122, 100, 20
    statictext  #main, "Zip:",         20, 142, 20, 20
    statictext  #main, " E-Mail 1:",     20, 162, 60, 20
    statictext  #main, " E-Mail 2:",     20, 182, 60, 20
    statictext  #main, " Notes: No commas or Return key",      500, 25, 300, 20

    statictext  #main, " Contacts:",   20, 235, 100, 15
    statictext  #main.totRecs, " ",    30, 265, 30, 20
    
       ' buttons
   button #main.btnSave, "Save", [btnSaveClicked],   UL, 375, 480, 75, 25
    button #main.btnExit, "Exit", [btnExitClicked],   UL, 375, 510, 75, 25
    button #main.btnClear,"Clear",[btnClearClicked],  UL, 375, 450, 75, 25
    button #main.btnEdit, "Edit Help", [btnEditHelpClicked], UL, 210, 540, 80, 22
    button #main.btnHelp, "?", [btnHelpClicked],        UR, 15, 4, 18, 18
    button #main.btnSaveEdit, "Save Edit",[btnSaveEdit] ,UL, 295, 540, 60, 22
    button #main.btnDelete,"Delete",[btnDeleteClicked], UL, 150, 540, 55, 22

    stylebits #main.lbx,  _ES_LEFT,  _WS_BORDER, 0, 0
    listbox #main.lbx, address$(, [displayContactInfo],  150, 230, 205, 300
    statictext #main.helpme, "", 350, 2, 40, 15
    
    'WAIT
   
   [openMainWindow]
    open "Address Cardfile" for window_nf as #main
        #main, "trapclose [btnExitClicked]"
        #main, "font ms_sans_serif 11"
       
       
    [btnExitClicked]
    Confirm "Close Address Cardfile?"; ans$
        if ans$= "no" then WAIT
    open "contactme.bak" for output as #copy
    close #original
    timer 500, [null]
    wait
    [null]
    timer 0
'shut down
    close #main
END   
guest
Site Admin
Posts: 198
Joined: Tue Apr 03, 2018 1:34 pm

Re: ADDRESS MANAGER

Post by guest »

RNBW wrote: Sun Jan 03, 2021 6:32 pm the position of Stylebits is important and MUST come after the related textbox otherwise it relates to the texbox preceding it.
Because of your FOR loop, you effectively have code like this:

Code: Select all

           TextBox #main.tb, hPos, (bHt)*i, bWidth+1, bHt+1
           Stylebits #main.tb, _ES_LEFT, _WS_BORDER, 0, 0
           TextBox #main.tb, 500, 50, 300, 480
....
Only you know whether the Stylebits should be associated with the preceding or following Textbox, so the behaviour is not a "quirk" but a not unreasonable lack of psychic powers on behalf of LB and LBB!
RNBW
Posts: 68
Joined: Thu Apr 05, 2018 9:21 pm

Re: ADDRESS MANAGER

Post by RNBW »

Richard

i hear what you are saying, but I didn't just put the statements in a FOR..NEXT loop, I put the statements in a SELECT CASE within the FOR..NEXT loop. The Stylebits and textbox statements come under CASE 10 and I would expect that in evaluating CASE 10 all other CASE statements would be ignored, but clearly it is not. Likewise, when evaluating CASE 1 to 9, I would expect that CASE 10 was ignored.
guest
Site Admin
Posts: 198
Joined: Tue Apr 03, 2018 1:34 pm

Re: ADDRESS MANAGER

Post by guest »

RNBW wrote: Mon Jan 04, 2021 5:30 pmI would expect that in evaluating CASE 10 all other CASE statements would be ignored, but clearly it is not. Likewise, when evaluating CASE 1 to 9, I would expect that CASE 10 was ignored.
You are still not seeing it. Unroll the loop so that there is neither a for...next nor a select statement. What you are left with is the code that LB/LBB actually executes when you run your program. To save you the trouble, here is your program with the loop unrolled:

Code: Select all

nomainwin

    WindowWidth = 830
    WindowHeight = 610
    UpperLeftX = 20
    UpperLeftY = 20
    
    '------------------------------------------------------------------
     'Set up the Textboxes
     ' NOTE that Stylebits must follow the Textbox statements!
     '-----------------------------------------------------------------
    TextboxColor$ = "white"
    print: print
    hPos = 150: bWidth = 300:  bHt = 20: Row = 10
    bWidth2 = 130: bWidth3 = 110

           TextBox #main.tb, hPos, (bHt)*1, bWidth+1, bHt+1
           Stylebits #main.tb, _ES_LEFT, _WS_BORDER, 0, 0
           TB$(1) = "#main.tb"; "_r";i      
           TextBox #main.tb, hPos, (bHt)*2, bWidth+1, bHt+1
           Stylebits #main.tb, _ES_LEFT, _WS_BORDER, 0, 0
           TB$(2) = "#main.tb"; "_r";i      
           TextBox #main.tb, hPos, (bHt)*3, bWidth+1, bHt+1
           Stylebits #main.tb, _ES_LEFT, _WS_BORDER, 0, 0
           TB$(3) = "#main.tb"; "_r";i      
           TextBox #main.tb, hPos, (bHt)*4, bWidth+1, bHt+1
           Stylebits #main.tb, _ES_LEFT, _WS_BORDER, 0, 0
           TB$(4) = "#main.tb"; "_r";i      
           TextBox #main.tb, hPos, (bHt)*5, bWidth+1, bHt+1
           Stylebits #main.tb, _ES_LEFT, _WS_BORDER, 0, 0
           TB$(5) = "#main.tb"; "_r";i      
           TextBox #main.tb, hPos, (bHt)*6, bWidth+1, bHt+1
           Stylebits #main.tb, _ES_LEFT, _WS_BORDER, 0, 0
           TB$(6) = "#main.tb"; "_r";i      
           TextBox #main.tb, hPos, (bHt)*7, bWidth+1, bHt+1
           Stylebits #main.tb, _ES_LEFT, _WS_BORDER, 0, 0
           TB$(7) = "#main.tb"; "_r";i      
           TextBox #main.tb, hPos, (bHt)*8, bWidth+1, bHt+1
           Stylebits #main.tb, _ES_LEFT, _WS_BORDER, 0, 0
           TB$(8) = "#main.tb"; "_r";i      
           TextBox #main.tb, hPos, (bHt)*9, bWidth+1, bHt+1
           Stylebits #main.tb, _ES_LEFT, _WS_BORDER, 0, 0
           TB$(9) = "#main.tb"; "_r";i      
           TextBox #main.tb, 500, 50, 300, 480
           Stylebits #main.tb, _ES_LEFT OR _WS_VSCROLL OR _ES_MULTILINE, _WS_BORDER OR _ES_AUTOHSCROLL, 0, 0
           maphandle #main.tb, TB$(10)
   
       ' Labels
    statictext  #main, " Name/Company:",       20, 22, 110, 20
    statictext  #main, "Tel:",       20, 42, 45, 20
    statictext  #main, "Mob:",        20, 62, 35, 20
    statictext  #main, "Address:",    20, 82, 100, 20
    statictext  #main, "City:",    20, 102, 45, 20
    statictext  #main, "County:",          20, 122, 100, 20
    statictext  #main, "Zip:",         20, 142, 20, 20
    statictext  #main, " E-Mail 1:",     20, 162, 60, 20
    statictext  #main, " E-Mail 2:",     20, 182, 60, 20
    statictext  #main, " Notes: No commas or Return key",      500, 25, 300, 20

    statictext  #main, " Contacts:",   20, 235, 100, 15
    statictext  #main.totRecs, " ",    30, 265, 30, 20
    
       ' buttons
   button #main.btnSave, "Save", [btnSaveClicked],   UL, 375, 480, 75, 25
    button #main.btnExit, "Exit", [btnExitClicked],   UL, 375, 510, 75, 25
    button #main.btnClear,"Clear",[btnClearClicked],  UL, 375, 450, 75, 25
    button #main.btnEdit, "Edit Help", [btnEditHelpClicked], UL, 210, 540, 80, 22
    button #main.btnHelp, "?", [btnHelpClicked],        UR, 15, 4, 18, 18
    button #main.btnSaveEdit, "Save Edit",[btnSaveEdit] ,UL, 295, 540, 60, 22
    button #main.btnDelete,"Delete",[btnDeleteClicked], UL, 150, 540, 55, 22

    stylebits #main.lbx,  _ES_LEFT,  _WS_BORDER, 0, 0
    listbox #main.lbx, address$(, [displayContactInfo],  150, 230, 205, 300
    statictext #main.helpme, "", 350, 2, 40, 15
    
    'WAIT
   
   [openMainWindow]
    open "Address Cardfile" for window_nf as #main
        #main, "trapclose [btnExitClicked]"
        #main, "font ms_sans_serif 11"
       
       
    [btnExitClicked]
    Confirm "Close Address Cardfile?"; ans$
        if ans$= "no" then WAIT
    open "contactme.bak" for output as #copy
    close #original
    timer 500, [null]
    wait
    [null]
    timer 0
'shut down
    close #main
END
You should now see that the situation I described arises: there are many places where there is no way that LB/LBB can determine whether a Stylebits statement is intended to apply to the preceding or following Textbox statement.
RNBW
Posts: 68
Joined: Thu Apr 05, 2018 9:21 pm

Re: ADDRESS MANAGER

Post by RNBW »

Or maybe if I moved maphandle out of the Select Case section and dropped it down the code to just above next and then had the Stylebits before the textbox and it works as I expected it to. However, I still think that logically you should produce the textbox before deciding what format it should take.

Code: Select all

    nomainwin

    WindowWidth = 830
    WindowHeight = 610
    UpperLeftX = 20
    UpperLeftY = 20
    
    '------------------------------------------------------------------
     'Set up the Textboxes
     ' NOTE that Stylebits must follow the Textbox statements!
     '-----------------------------------------------------------------
    TextboxColor$ = "white"
    print: print
    hPos = 150: bWidth = 300:  bHt = 20: Row = 10
    bWidth2 = 130: bWidth3 = 110
    For i = 1 to Row
       Select Case i
          case 1, 2, 3, 4, 5, 6, 7, 8, 9
           TextBox #main.tb, hPos, (bHt)*i, bWidth+1, bHt+1
           Stylebits #main.tb, _ES_LEFT, _WS_BORDER, 0, 0
           TB$(i) = "#main.tb"; "_r";i      
         case 10
           ' Now the position of Stylebits doesn't matter
           Stylebits #main.tb, _ES_LEFT OR _WS_VSCROLL OR _ES_MULTILINE, _WS_BORDER OR _ES_AUTOHSCROLL, 0, 0
           TextBox #main.tb, 500, 50, 300, 480
           'Stylebits #main.tb, _ES_LEFT OR _WS_VSCROLL OR _ES_MULTILINE, _WS_BORDER OR _ES_AUTOHSCROLL, 0, 0
           'maphandle #main.tb, TB$(i)     ' I think this statement is in the wrong location.
       end select 
       maphandle #main.tb, TB$(i)   ' maphandle moved here
   next
   
       ' Labels
    statictext  #main, " Name/Company:",       20, 22, 110, 20
    statictext  #main, "Tel:",       20, 42, 45, 20
    statictext  #main, "Mob:",        20, 62, 35, 20
    statictext  #main, "Address:",    20, 82, 100, 20
    statictext  #main, "City:",    20, 102, 45, 20
    statictext  #main, "County:",          20, 122, 100, 20
    statictext  #main, "Zip:",         20, 142, 20, 20
    statictext  #main, " E-Mail 1:",     20, 162, 60, 20
    statictext  #main, " E-Mail 2:",     20, 182, 60, 20
    statictext  #main, " Notes: No commas or Return key",      500, 25, 300, 20

    statictext  #main, " Contacts:",   20, 235, 100, 15
    statictext  #main.totRecs, " ",    30, 265, 30, 20
    
       ' buttons
   button #main.btnSave, "Save", [btnSaveClicked],   UL, 375, 480, 75, 25
    button #main.btnExit, "Exit", [btnExitClicked],   UL, 375, 510, 75, 25
    button #main.btnClear,"Clear",[btnClearClicked],  UL, 375, 450, 75, 25
    button #main.btnEdit, "Edit Help", [btnEditHelpClicked], UL, 210, 540, 80, 22
    button #main.btnHelp, "?", [btnHelpClicked],        UR, 15, 4, 18, 18
    button #main.btnSaveEdit, "Save Edit",[btnSaveEdit] ,UL, 295, 540, 60, 22
    button #main.btnDelete,"Delete",[btnDeleteClicked], UL, 150, 540, 55, 22

    stylebits #main.lbx,  _ES_LEFT,  _WS_BORDER, 0, 0
    listbox #main.lbx, address$(, [displayContactInfo],  150, 230, 205, 300
    statictext #main.helpme, "", 350, 2, 40, 15
    
    'WAIT
   
   [openMainWindow]
    open "Address Cardfile" for window_nf as #main
        #main, "trapclose [btnExitClicked]"
        #main, "font ms_sans_serif 11"      
       
    [btnExitClicked]
    Confirm "Close Address Cardfile?"; ans$
        if ans$= "no" then WAIT
    open "contactme.bak" for output as #copy
    close #original
    timer 500, [null]
    wait
    [null]
    timer 0
'shut down
    close #main
END   
   
guest
Site Admin
Posts: 198
Joined: Tue Apr 03, 2018 1:34 pm

Re: ADDRESS MANAGER

Post by guest »

RNBW wrote: Tue Jan 05, 2021 4:45 pmOr maybe if I moved maphandle out of the Select Case section and dropped it down the code to just above next
You should have done that from the start, I'm surprised that it ever worked the way you had it.
I still think that logically you should produce the textbox before deciding what format it should take.
I don't consider one to be more "logical" than the other, they are both perfectly reasonable approaches. However I would have preferred LB to accept only one of them; I don't really care which, but accepting either is what can result in an ambiguity.

At the Windows API level it is all one operation anyway: you create the control and specify its style (and several other parameters) at the same time; ideally LB would have done that too but I'm pretty sure that the Textbox statement came first and Stylebits was a later addition, hence the rather awkward syntax.

In BBC BASIC (both BBC BASIC for Windows and BBC BASIC for SDL 2.0) you do specify the style when the control is created.
RNBW
Posts: 68
Joined: Thu Apr 05, 2018 9:21 pm

Re: ADDRESS MANAGER

Post by RNBW »

Hi Richard
It's my poor coding. It was under my nose and I couldn't see it!
As you say, BBC Basic and most other languages I know have a flag at the end of the textbox statement, which is why I think it is more logical; draw the control and then decide what you want to do with it.
As you say Stylebits was probably an afterthought.

I've decided that with my coding, Stylebits will follow the control. It gives a more universal feel.

Anyway, Happy New Year and keep safe.

Ray