Browser sorting.

Greetings to everyone.

I have been working on another project and haven't visited this board in quite some time. But now I am back to my favorite progress haha. This time I have a program that lists all extra materials that our company has. My task is to sort the little browser by date of entry, rather then by the shape of the pieces, which it currently does. Here is the delicious code :cool:

I am guessing I should introduce some kind of sort call in browse definitions. In other programs this seems to be accomplished by "FIND LAST" "FIND FIRST" statements. Which would be ok, if I somehow could tell the browser to look for the last record. (I do have an index for it by the way)

Code:
 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12 GUI
&ANALYZE-RESUME
/* Connected Databases 
          shop             PROGRESS
*/
&Scoped-define WINDOW-NAME C-Win
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS C-Win 


CREATE WIDGET-POOL.


/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK 

/* ********************  Preprocessor Definitions  ******************** */

&Scoped-define PROCEDURE-TYPE Window

/* Name of first Frame and/or Browse and/or first Query                 */
&Scoped-define FRAME-NAME DEFAULT-FRAME
&Scoped-define BROWSE-NAME BROWSE-4

/* Internal Tables (found by Frame, Query & Browse Queries)             */
&Scoped-define INTERNAL-TABLES xmatl

/* Definitions for BROWSE BROWSE-4                                      */
&Scoped-define FIELDS-IN-QUERY-BROWSE-4 xmatl.date1 xmatl.shape xmatl.mattyp xmatl.dimen ~
 xmatl.qty1 xmatl.length xmatl.location xmatl.note1  
&Scoped-define ENABLED-FIELDS-IN-QUERY-BROWSE-4 xmatl.date1 xmatl.shape xmatl.dimen ~
xmatl.mattyp xmatl.qty1 xmatl.length xmatl.location xmatl.note1  
&Scoped-define FIELD-PAIRS-IN-QUERY-BROWSE-4~
 ~{&FP1}shape ~{&FP2}shape ~{&FP3}~
 ~{&FP1}dimen ~{&FP2}dimen ~{&FP3}~
 ~{&FP1}mattyp ~{&FP2}mattyp ~{&FP3}~
 ~{&FP1}qty1 ~{&FP2}qty1 ~{&FP3}~
 ~{&FP1}length ~{&FP2}length ~{&FP3}~
 ~{&FP1}location ~{&FP2}location ~{&FP3}~
 ~{&FP1}note1 ~{&FP2}note1 ~{&FP3}~
 ~{&FP1}date1 ~{&FP2}date1 ~{&FP3}
&Scoped-define ENABLED-TABLES-IN-QUERY-BROWSE-4 xmatl
&Scoped-define FIRST-ENABLED-TABLE-IN-QUERY-BROWSE-4 xmatl
&Scoped-define OPEN-QUERY-BROWSE-4 OPEN QUERY BROWSE-4 FOR EACH xmatl SHARE-LOCK.
&Scoped-define TABLES-IN-QUERY-BROWSE-4 xmatl
&Scoped-define FIRST-TABLE-IN-QUERY-BROWSE-4 xmatl


/* Definitions for FRAME DEFAULT-FRAME                                  */
&Scoped-define OPEN-BROWSERS-IN-QUERY-DEFAULT-FRAME ~
    ~{&OPEN-QUERY-BROWSE-4}

/* Standard List Definitions                                            */
&Scoped-Define ENABLED-OBJECTS BROWSE-4 

/* Custom List Definitions                                              */
/* List-1,List-2,List-3,List-4,List-5,List-6                            */

/* _UIB-PREPROCESSOR-BLOCK-END */
&ANALYZE-RESUME

/* Local Variable Definitions */
{incl\globals.i}

/* Housekeeping variables */
{incl\sysvar.i}
def new shared var vMattyp as char.
/* ***********************  Control Definitions  ********************** */

/* Define the widget handle for the window                              */
DEFINE VAR C-Win AS WIDGET-HANDLE NO-UNDO.

/* Menu Definitions                                                     */
DEFINE MENU POPUP-MENU-BROWSE-4 
       MENU-ITEM m_InsertLine   LABEL "InsertLine"    
       MENU-ITEM m_DupLine      LABEL "DupLine"       
       RULE
       MENU-ITEM m_DeleteLine   LABEL "DeleteLine"  
       rule
       menu-item m_Printlist   Label "PrintList"  .


/* Definitions of the field level widgets                               */
/* Query definitions                                                    */
&ANALYZE-SUSPEND
DEFINE QUERY BROWSE-4 FOR 
      xmatl SCROLLING.
&ANALYZE-RESUME

/* Browse definitions                                                   */
DEFINE BROWSE BROWSE-4
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _DISPLAY-FIELDS BROWSE-4 C-Win _STRUCTURED
  QUERY BROWSE-4 SHARE-LOCK NO-WAIT DISPLAY
      
    xmatl.date1
    xmatl.shape
      xmatl.mattyp
      xmatl.dimen

      xmatl.qty1
      xmatl.length
      xmatl.location
      xmatl.note1
  ENABLE
      
    
    xmatl.date1
    xmatl.shape
      xmatl.dimen
      xmatl.mattyp
      
        xmatl.qty1
      xmatl.length
      xmatl.location
      xmatl.note1
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

    WITH NO-ROW-MARKERS SIZE 173 BY 18.1.


/* ************************  Frame Definitions  *********************** */

DEFINE FRAME DEFAULT-FRAME
     BROWSE-4 AT ROW 7.43 COL 1
    WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY 
         SIDE-LABELS NO-UNDERLINE THREE-D 
         AT COL 1 ROW 1
         SIZE 175 BY 25.33.
        


/* *********************** Procedure Settings ************************ */

&ANALYZE-SUSPEND _PROCEDURE-SETTINGS
/* Settings for THIS-PROCEDURE
   Type: Window
   Allow: Basic,Browse,DB-Fields,Window,Query
   Other Settings: COMPILE
 */
&ANALYZE-RESUME _END-PROCEDURE-SETTINGS

/* *************************  Create Window  ************************** */

&ANALYZE-SUSPEND _CREATE-WINDOW
IF SESSION:DISPLAY-TYPE = "GUI":U THEN
  CREATE WINDOW C-Win ASSIGN
         HIDDEN             = YES
         TITLE              = "Extra CMRP Matl"
         HEIGHT             = 26.24
         WIDTH              = 178.4
         MAX-HEIGHT         = 34.33
         MAX-WIDTH          = 204.8
         VIRTUAL-HEIGHT     = 34.33
         VIRTUAL-WIDTH      = 204.8
         RESIZE             = yes
         SCROLL-BARS        = no
         STATUS-AREA        = no
         BGCOLOR            = 5
         
         FGCOLOR            = 2
         KEEP-FRAME-Z-ORDER = yes
         THREE-D            = yes
         MESSAGE-AREA       = no
         SENSITIVE          = yes.
ELSE {&WINDOW-NAME} = CURRENT-WINDOW.
/* END WINDOW DEFINITION                                                */
&ANALYZE-RESUME


/* ***************  Runtime Attributes and UIB Settings  ************** */

&ANALYZE-SUSPEND _RUN-TIME-ATTRIBUTES
/* SETTINGS FOR WINDOW C-Win
  VISIBLE,,RUN-PERSISTENT                                               */
/* SETTINGS FOR FRAME DEFAULT-FRAME
                                                                        */
/* BROWSE-TAB BROWSE-4 1 DEFAULT-FRAME */
ASSIGN 
       BROWSE-4:POPUP-MENU IN FRAME DEFAULT-FRAME         = MENU POPUP-MENU-BROWSE-4:HANDLE.

IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win)
THEN C-Win:HIDDEN = no.

/* _RUN-TIME-ATTRIBUTES-END */
&ANALYZE-RESUME


/* Setting information for Queries and Browse Widgets fields            */

&ANALYZE-SUSPEND _QUERY-BLOCK BROWSE BROWSE-4
/* Query rebuild information for BROWSE BROWSE-4
     _TblList          = "shop.xmatl"
     _Options          = "SHARE-LOCK"
     _FldNameList[1]   > shop.xmatl.shape
"shape" ? ? "character" ? ? ? ? ? ? yes ?
     _FldNameList[2]   > shop.xmatl.mattyp
"mattyp" ? ? "character" ? ? ? ? ? ? yes ?

     _FldNameList[3]   > shop.xmatl.dimen
"dimen" ? ? "character" ? ? ? ? ? ? yes ?

     _FldNameList[4]   > shop.xmatl.qty1
"qty1" ? ? "decimal" ? ? ? ? ? ? yes ?
     _FldNameList[5]   > shop.xmatl.length
"length" ? ? "decimal" ? ? ? ? ? ? yes ?
     _FldNameList[6]   > shop.xmatl.location
"location" ? ? "character" ? ? ? ? ? ? yes ?
     _FldNameList[7]   > shop.xmatl.note1
"note1" ? ? "character" ? ? ? ? ? ? yes ?
     _FldNameList[8]   > shop.xmatl.date1
"date1" ? ? "date" ? ? ? ? ? ? yes ?
     _Query            is OPENED
*/  /* BROWSE BROWSE-4 */
&ANALYZE-RESUME

 




/* ************************  Control Triggers  ************************ */

&Scoped-define SELF-NAME C-Win
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL C-Win C-Win
ON END-ERROR OF C-Win /* Extra CMRP Matl */
OR ENDKEY OF {&WINDOW-NAME} ANYWHERE DO:
  /* This case occurs when the user presses the "Esc" key.
     In a persistently run window, just ignore this.  If we did not, the
     application would exit. */
  IF THIS-PROCEDURE:PERSISTENT THEN RETURN NO-APPLY.
END.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&Scoped-define SELF-NAME m_InsertLine
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL m_InsertLine C-Win
ON CHOOSE OF MENU-ITEM m_InsertLine 
DO:
create xmatl.
assign xmatl.date1 = today
       xmatl.note1 = user-login.
  RUN enable_UI.
END.

&Scoped-define SELF-NAME m_printlist
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL m_printlist C-Win
ON CHOOSE OF MENU-ITEM m_printlist
DO:


run main\get-name.p (output g-temp-filename).

   output to value(g-temp-filename) page-size 111.

    form header "EXTRA MATERIAL LIST" with width 150 stream-io frame rpt-hdr page-top no-box no-labels.
    view frame rpt-hdr.


 for each xmatl :
 display xmatl.shape format "X(10)" at 1
           xmatl.dimen format "x(20)" at 20
           qty1 
           length
            location note1  with width 150.
    end. /*year*/        

  output close.
  run main\viewfile.w (yes).
  return.



END.



&Scoped-define SELF-NAME m_DeleteLine
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL m_DeleteLine C-Win
ON CHOOSE OF MENU-ITEM m_DeleteLine 
DO:
  message " Delete Line :" xmatl.shape + xmatl.mattyp + xmatl.dimen "? "
    view-as alert-box question buttons YES-NO
    update delcheck as log auto-return.
  
  if delcheck then do: 
delete xmatl.
  RUN enable_UI.
  end.
END.


&Scoped-define SELF-NAME m_DupLine
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL m_DupLine C-Win
ON CHOOSE OF MENU-ITEM m_DupLine 
DO:
create xmatl.
assign xmatl.shape = xmatl.shape:SCREEN-VALUE IN BROWSE {&BROWSE-NAME}.
assign xmatl.dimen = xmatl.dimen:SCREEN-VALUE IN BROWSE {&BROWSE-NAME}.
assign xmatl.mattyp = xmatl.mattyp:SCREEN-VALUE IN BROWSE {&BROWSE-NAME}.
assign xmatl.location = xmatl.location:SCREEN-VALUE IN BROWSE {&BROWSE-NAME}.
assign xmatl.note1 = xmatl.note1:SCREEN-VALUE IN BROWSE {&BROWSE-NAME}.
assign xmatl.qty1 = dec(xmatl.qty1:SCREEN-VALUE IN BROWSE {&BROWSE-NAME}).
assign xmatl.length = dec(xmatl.length:SCREEN-VALUE IN BROWSE {&BROWSE-NAME}).
assign xmatl.date1 = today.
  RUN enable_UI.
END.



/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

ON CTRL-L OF xmatl.shape IN BROWSE {&BROWSE-NAME}
DO:
 {incl\run.i &program="setup\shapesc.w"
              &run_method="DIALOG" } 
  
  if g-recid = ? then 
    return "error".
     
  find shape where recid(shape) = g-recid no-lock NO-ERROR.
  if avail shape then do:          
    assign 
      xmatl.shape:SCREEN-VALUE IN BROWSE {&BROWSE-NAME} = 
        shape.shape.
      apply "TAB" to SELF.
  end.  
  else
    return "error".  
  return.

run p_assignline.
  IF CAN-DO("ERROR,CANCEL",RETURN-VALUE) THEN RETURN no-apply.
END.


ON CTRL-L OF xmatl.mattyp IN BROWSE {&BROWSE-NAME}
DO:
  {incl\run.i &program="setup\mattypsc.w"
              &run_method="DIALOG" } 
  
  if g-recid = ? then 
    return "error".
     
  find mattyp where recid(mattyp) = g-recid no-lock NO-ERROR.
  if avail mattyp then do:          
    assign 
      xmatl.mattyp:SCREEN-VALUE IN BROWSE {&BROWSE-NAME} = mattyp.mattyp.
      
      apply "TAB" to SELF.
  end.  
  else
    return "error".  
    
  return.
run p_assignline.
  IF CAN-DO("ERROR,CANCEL",RETURN-VALUE) THEN RETURN no-apply.
END.

ON CTRL-L OF xmatl.dimen IN BROWSE {&BROWSE-NAME}
DO:

vMattyp = xmatl.mattyp:screen-value in browse {&browse-name}.

if xmatl.shape:screen-value in browse {&browse-name} = "angle" then do:
 
  {incl\run.i &program="setup/anglesc.w"
              &run_method="DIALOG" }  
   if g-recid = ? then return "error".
   find angle where recid(angle) = g-recid no-lock NO-ERROR.
   if avail angle then do:          
     assign 
      xmatl.dimen:SCREEN-VALUE IN BROWSE {&BROWSE-NAME} = angle.dimen.
      apply "TAB" to SELF.
   end.  
  else
    return "error".  
end.
else if xmatl.shape:screen-value in browse {&browse-name} = "beam" then do:
  {incl\run.i &program="setup/beamsc.w"
              &run_method="DIALOG" }  
   if g-recid = ? then return "error".
   find beam where recid(beam) = g-recid no-lock NO-ERROR.
   if avail beam then do:          
     assign 
      xmatl.dimen:SCREEN-VALUE IN BROWSE {&BROWSE-NAME} = beam.dimen.

      apply "TAB" to SELF.
   end.  
  else
    return "error".  
end.
else if xmatl.shape:screen-value in browse {&browse-name} = "sq tube" then do:
  {incl\run.i &program="setup/stubesc.w"
              &run_method="DIALOG" }  
   if g-recid = ? then return "error".
   find stube where recid(stube) = g-recid no-lock NO-ERROR.
   if avail stube then do:          
     assign 
      xmatl.dimen:SCREEN-VALUE IN BROWSE {&BROWSE-NAME} = stube.dimen.

      apply "TAB" to SELF.
   end.  
  else
    return "error".  
end.
else if xmatl.shape:screen-value in browse {&browse-name} = "channel" then do:
  {incl\run.i &program="setup/channelsc.w"
              &run_method="DIALOG" }  
   if g-recid = ? then return "error".    find channel where recid(channel) = g-recid no-lock NO-ERROR.
   if avail channel then do:          
     assign 
      xmatl.dimen:SCREEN-VALUE IN BROWSE {&BROWSE-NAME} = channel.dimen.

      apply "TAB" to SELF.
   end.  
  else
    return "error".  
end.
else if xmatl.shape:screen-value in browse {&browse-name} = "rect tube" then do:
  {incl\run.i &program="setup/rtubesc.w"
              &run_method="DIALOG" }  
   if g-recid = ? then return "error".
   find rtube where recid(rtube) = g-recid no-lock NO-ERROR.
   if avail rtube then do:          
     assign 
      xmatl.dimen:SCREEN-VALUE IN BROWSE {&BROWSE-NAME} = rtube.dimen.

      apply "TAB" to SELF.
   end.  
  else
    return "error".  
end.
else if xmatl.shape:screen-value in browse {&browse-name} = "tee" then do:
  {incl\run.i &program="setup/teesc.w"
              &run_method="DIALOG" }  
   if g-recid = ? then return "error".
   find tee where recid(tee) = g-recid no-lock NO-ERROR.
   if avail tee then do:          
     assign 
      xmatl.dimen:SCREEN-VALUE IN BROWSE {&BROWSE-NAME} = tee.dimen.
      
      apply "TAB" to SELF.
   end.  
  else
    return "error".  
end.
    
    
    run p_assignline.    

  IF CAN-DO("ERROR,CANCEL",RETURN-VALUE) THEN RETURN no-apply.
END.



on leave of xmatl.shape run p_assignline.
on leave of xmatl.mattyp run p_assignline.

on leave of xmatl.dimen run p_assignline.
on leave of xmatl.length run p_assignline.
on leave of xmatl.note1 run p_assignline.
on leave of xmatl.location run p_assignline.
on leave of xmatl.qty1 run p_assignline.

on leave of xmatl.date1 run p_assignline.



&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL C-Win C-Win
ON WINDOW-CLOSE OF C-Win /* Extra CMRP Matl */
DO:
  /* This event will close the window and terminate the procedure.  */
  APPLY "CLOSE":U TO THIS-PROCEDURE.
  RETURN NO-APPLY.
END.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&Scoped-define BROWSE-NAME BROWSE-4
&UNDEFINE SELF-NAME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK C-Win 


/* ***************************  Main Block  *************************** */

/* Set CURRENT-WINDOW: this will parent dialog-boxes and frames.        */
ASSIGN CURRENT-WINDOW                = {&WINDOW-NAME} 
       THIS-PROCEDURE:CURRENT-WINDOW = {&WINDOW-NAME}.

/* The CLOSE event can be used from inside or outside the procedure to  */
/* terminate it.                                                        */
ON CLOSE OF THIS-PROCEDURE 
   RUN disable_UI.

/* Best default for GUI applications is...                              */
PAUSE 0 BEFORE-HIDE.

/* Now enable the interface and wait for the exit condition.            */
/* (NOTE: handle ERROR and END-KEY so cleanup code will always fire.    */
MAIN-BLOCK:
DO ON ERROR   UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK
   ON END-KEY UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK:
   message "WELCOME to CMRP Extra Material." view-as alert-box. 

  RUN enable_UI.
  IF NOT THIS-PROCEDURE:PERSISTENT THEN
    WAIT-FOR CLOSE OF THIS-PROCEDURE.
END.






/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


/* **********************  Internal Procedures  *********************** */

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE disable_UI C-Win _DEFAULT-DISABLE
PROCEDURE disable_UI :
/*------------------------------------------------------------------------------
  Purpose:     DISABLE the User Interface
  Parameters:  <none>
  Notes:       Here we clean-up the user-interface by deleting
               dynamic widgets we have created and/or hide 
               frames.  This procedure is usually called when
               we are ready to "clean-up" after running.
------------------------------------------------------------------------------*/
  /* Delete the WINDOW we created */
  IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win)
  THEN DELETE WIDGET C-Win.
  IF THIS-PROCEDURE:PERSISTENT THEN DELETE PROCEDURE THIS-PROCEDURE.
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE enable_UI C-Win _DEFAULT-ENABLE
PROCEDURE enable_UI :

  ENABLE BROWSE-4 
      WITH FRAME DEFAULT-FRAME IN WINDOW C-Win.
  {&OPEN-BROWSERS-IN-QUERY-DEFAULT-FRAME}
  VIEW C-Win.
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE p_assignline C-Win _DEFAULT-ENABLE
PROCEDURE p_assignline :

/* assign xmatl.shape = xmatl.shape:screen-value in browse {&browse-name}.  */

APPLY "VALUE-CHANGED" TO BROWSE {&browse-name}.

xmatl.note3 = xmatl.dimen:screen-value + " " + xmatl.shape:screen-value + " " + xmatl.mattyp:screen-value .



END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

Thanks everyone for looking
 
Top