Announcement

Collapse
No announcement yet.

Listbox: sorted or unsorted options?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Listbox: sorted or unsorted options?

    Mystery: this bit of code gives the listbox in SORTED order. Using the option to specify the array name (ECsbm$) does the same. Since the %LBS_SORT style is absent, what can the reason be? By putting a MsgBox just before the "NEXT" of the loop, I could observe that (a) the strings are fetched in turn, as per original array, and (b) they are inserted in their alphabetical positions immediately.

    I downloaded from the BBS the several example files of Dave Navarro's, and in the bit which I used here, the REMARKS read:

    REMARKS: If the listbox does not have the %LBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into the list and the list is sorted.
    Code:
    '---------------------------------------------------------------------
    CallBack Function ECmenus()
     If CbMsg = %WM_COMMAND Then
      If CbCtl=1000 Or CbCtl=1001 Then
    
       ReDim ECsbm$(16)
    
       ECsbm$(1)="New quotation"
       ECsbm$(2)="Quotations in progress"
       ECsbm$(3)="Standard quotation"
       ECsbm$(4)="Ex-archive quotation"
       ECsbm$(5)="Worktickets menu"
       ECsbm$(6)="Set up standard jobs"
       ECsbm$(7)="JOB COSTING SUBMENU"
       ECsbm$(8)="Print setup files"
       ECsbm$(9)="Suppliers' price list report"
       ECsbm$(10)="Transfer archive to diskette"
       ECsbm$(11)="Ticket/time report"
       ECsbm$(12)="Ticket/sales report"
       ECsbm$(13)="Agents' commission report"
       ECsbm$(14)="Company stock selling prices"
       ECsbm$(15)="Time dockets checklist"
       ECsbm$(16)="Browse archived jobs"
    
       Control Add ListBox, pDlg&, %ID_EstSbm,, 140, 20, 120, 140 Call ECselect
       hFont = MakeFont("MS Sans Serif", 10)
       Dialog Send pDlg&, %WM_SETFONT, hFont, 1
       Control Handle pDlg&, %ID_EstSbm To hCtl&
       For i&=1 To 16
        RetVal& = LbAddString(hCtl&, ECsbm$(i&))
        Next
       End If
      End If
     End Function
    '----------------------------------------------------------------------
    Excerpt from BBS download:
    
    '  TITLE: LbAddString
    '   DESC: Add a string to a listbox.
    ' SYNTAX: RetVal = LbAddString(hListBox, Text$)
    'RETURNS: The return value is the zero-based index to the string in the    '         list box. The return value is %LB_ERR if an error occurs; the    '         return value is %LB_ERRSPACE if insufficient space is available  '         to store the new string.
    'REMARKS: If the listbox does not have the %LBS_SORT style, the string     '         is added to the end of the list. Otherwise, the string is  '         inserted into the list and the list is sorted.
    '
    FUNCTION LbAddString(BYVAL hListBox AS LONG, BYVAL Text AS STRING) AS LONG
      FUNCTION = SendMessage(hListBox, %LB_ADDSTRING, 0, STRPTR(Text))
    END FUNCTION
    '----------------------------------------------------------------------
    Last edited by Gary Beene; 19 Jul 2014, 08:05 PM. Reason: Code: tags

  • #2
    It's no mystery...

    The default style for a LISTBOX (%LBS_STANDARD) is made up of the %LBS_SORT and %LBS_NOTIFY styles (and an implicit %WS_TABSTOP is included too). This is detailed in the doc's in two places.

    To specifically exclude the sorted style, specify an explicit set of styles (in your CONTROL ADD statement) that do not include the %LBS_SORT style flag.


    -------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      I do like this:

      %MYSTYLE= %LBS_STANDARD Or %LBS_HASSTRINGS Or %LBS_USETABSTOPS Xor %LBS_SORT

      Best Regards Peter Scheutz
      Best Regards
      Peter Scheutz

      Comment


      • #4
        Thanks, Lance and Peter. Have just added an equate for general use:

        %LbxStyle=%LBS_STANDARD Or %LBS_HASSTRINGS Or %LBS_USETABSTOPS Xor %LBS_SORT

        (copied from yours, Peter). With this kind of help and those bits of programming such as Dave Navarro's on the PROGRAMMING Bbs, who needs the Petzold book ... ?!?! (Not really! my copy is on order and SHOULD be here this week)

        Comment


        • #5
          BTW, Lance, thanks also for your e-mail regarding the profile business. The e-mail address you quote is correct. All I would perhaps change on the profile is to space my name out (as Dieny du Toit i.p.o. DienyduToit) but I see no option |modify profile". Not serious.

          Comment

          Working...
          X