I have the following procedure,
I have checked the syntax in the appbuilder and it says that it is correct however when i open the form it then opens excel straight away and populates it with nothing. What is supposed to happen is the form opens, user puts order number into a fill in and then clicks the button to export the relevant data to Excel
Can someone please check my code?
cheers,
&ANALYZE-SUSPEND _VERSION-NUMBER AB_v10r12 GUI ADM2
&ANALYZE-RESUME
&Scoped-define WINDOW-NAME wWin
{adecomm/appserv.i}
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS wWin
CREATE WIDGET-POOL.
/* *************************** Definitions ************************** */
&SCOPED-DEFINE TableName ContractHdr
/* Parameters Definitions --- */
/* Local Variable Definitions --- */
{inc/stdhdr.i}
{inc/progname.i} /* Program Name Info - Accessed by ALT-P */
{inc/pers00.i NEW SHARED} /* Standard Variables and Images */
{inc/menubtns.i SHARED} /* Toolbar Buttons */
DEFINE VARIABLE chExcelApplication AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE ch-Workbook AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE ch-Worksheet AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE iRow AS INTEGER INITIAL 1 NO-UNDO.
DEFINE VARIABLE cRow AS CHARACTER NO-UNDO.
DEFINE VARIABLE cCell AS CHARACTER NO-UNDO.
DEFINE VARIABLE OrderNumber AS CHARACTER NO-UNDO.
/****************************** BUFFERS ******************************/
DEF BUFFER buf-invtrans FOR InvTrans.
DEF TEMP-TABLE tt-prodqry NO-UNDO
FIELD prodppn LIKE InvTrans.itemProdPPN
FIELD ItemSerial LIKE InvTrans.ItemSerial
FIELD prodndate LIKE Invtrans.ItemProdnDate
FIELD station LIKE TxCarton.TxStation
FIELD prodtime LIKE txcarton.TxTime.
{src/adm2/widgetprto.i}
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
/* ******************** Preprocessor Definitions ******************** */
&Scoped-define PROCEDURE-TYPE SmartWindow
&Scoped-define DB-AWARE no
&Scoped-define ADM-CONTAINER WINDOW
&Scoped-define ADM-SUPPORTED-LINKS Data-Target,Data-Source,Page-Target,Update-Source,Update-Target,Filter-target,Filter-Source
/* Name of designated FRAME-NAME and/or first browse and/or first query */
&Scoped-define FRAME-NAME fMain
&Scoped-define INTERNAL-TABLES InvTrans TxCarton
/* Standard List Definitions */
&Scoped-Define ENABLED-OBJECTS ordnum BUTTON-1
&Scoped-Define DISPLAYED-OBJECTS ordnum
/* Custom List Definitions */
/* List-1,List-2,List-3,List-4,List-5,List-6 */
/* _UIB-PREPROCESSOR-BLOCK-END */
&ANALYZE-RESUME
/* *********************** Control Definitions ********************** */
/* Define the widget handle for the window */
DEFINE VAR wWin AS WIDGET-HANDLE NO-UNDO.
/* Definitions of the field level widgets */
DEFINE BUTTON BUTTON-1
LABEL "Export to Excel"
SIZE 19 BY .95.
DEFINE VARIABLE ordnum AS INTEGER FORMAT "->>>>>>9":U INITIAL 0
LABEL "Order Number"
VIEW-AS FILL-IN
SIZE 14 BY 1 NO-UNDO.
/* ************************ Frame Definitions *********************** */
DEFINE FRAME fMain
ordnum AT ROW 2.43 COL 15 COLON-ALIGNED WIDGET-ID 2
BUTTON-1 AT ROW 2.43 COL 38 WIDGET-ID 4
WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY
SIDE-LABELS NO-UNDERLINE THREE-D
AT COL 1 ROW 1
SIZE 80 BY 17 WIDGET-ID 100.
/* *********************** Procedure Settings ************************ */
&ANALYZE-SUSPEND _PROCEDURE-SETTINGS
/* Settings for THIS-PROCEDURE
Type: SmartWindow
Allow: Basic,Browse,DB-Fields,Query,Smart,Window
Container Links: Data-Target,Data-Source,Page-Target,Update-Source,Update-Target,Filter-target,Filter-Source
Other Settings: APPSERVER
*/
&ANALYZE-RESUME _END-PROCEDURE-SETTINGS
/* ************************* Create Window ************************** */
&ANALYZE-SUSPEND _CREATE-WINDOW
IF SESSION:DISPLAY-TYPE = "GUI":U THEN
CREATE WINDOW wWin ASSIGN
HIDDEN = YES
TITLE = "Production Query"
HEIGHT = 17
WIDTH = 80
MAX-HEIGHT = 28.81
MAX-WIDTH = 146.2
VIRTUAL-HEIGHT = 28.81
VIRTUAL-WIDTH = 146.2
RESIZE = no
SCROLL-BARS = no
STATUS-AREA = no
BGCOLOR = ?
FGCOLOR = ?
THREE-D = yes
MESSAGE-AREA = no
SENSITIVE = yes.
ELSE {&WINDOW-NAME} = CURRENT-WINDOW.
/* END WINDOW DEFINITION */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _XFTR "SmartWindowCues" wWin _INLINE
/* Actions: adecomm/_so-cue.w ? adecomm/_so-cued.p ? adecomm/_so-cuew.p */
/* SmartWindow,ab,49271
Destroy on next read */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB wWin
/* ************************* Included-Libraries *********************** */
{src/adm2/containr.i}
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
/* *********** Runtime Attributes and AppBuilder Settings *********** */
&ANALYZE-SUSPEND _RUN-TIME-ATTRIBUTES
/* SETTINGS FOR WINDOW wWin
VISIBLE,,RUN-PERSISTENT */
/* SETTINGS FOR FRAME fMain
FRAME-NAME */
IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(wWin)
THEN wWin:HIDDEN = yes.
/* _RUN-TIME-ATTRIBUTES-END */
&ANALYZE-RESUME
/* ************************ Control Triggers ************************ */
&Scoped-define SELF-NAME wWin
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL wWin wWin
ON END-ERROR OF wWin /* <insert SmartWindow title> */
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
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL wWin wWin
ON WINDOW-CLOSE OF wWin /* <insert SmartWindow title> */
DO:
/* This ADM code must be left here in order for the SmartWindow
and its descendents to terminate properly on exit. */
APPLY "CLOSE":U TO THIS-PROCEDURE.
RETURN NO-APPLY.
END.
&Scoped-define SELF-NAME BUTTON-1
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL BUTTON-1 wWin
ON CHOOSE OF BUTTON-1 IN FRAME fMain /* Export to Excel */
DO:
OrderNumber = STRING (ordnum:SCREEN-VALUE).
EMPTY TEMP-TABLE tt-prodqry.
SESSION:SET-WAIT-STATE("GENERAL").
FOR EACH InvTrans WHERE InvTrans.OrderNo = OrderNumber
AND InvTrans.TxEvent = "lo" NO-LOCK,
EACH TxCarton WHERE TxCarton.TxBarcode = InvTrans.Barcode NO-LOCK
BY InvTrans.ItemProdPPN.
CREATE tt-prodqry.
ASSIGN
tt-prodqry.prodppn = IF AVAILABLE InvTrans THEN
InvTrans.itemProdPPN
ELSE "unknown"
tt-prodqry.ItemSerial = InvTrans.ItemSerial
tt-prodqry.prodndate = Invtrans.ItemProdnDate
tt-prodqry.station = TxCarton.TxStation
tt-prodqry.prodtime = txcarton.TxTime.
END.
END.
DO:
CREATE "Excel.Application" chExcelApplication.
ch-Workbook = chExcelApplication:Workbooks:ADD().
ch-WorkSheet = chExcelApplication:Sheets:Item(1).
ch-Workbook:enable-events("ExcelSS").
ch-Worksheet:enable-events("SSExcelSS").
ASSIGN
ch-Worksheet:COLUMNS("A"):ColumnWidth = 5
ch-Worksheet:COLUMNS("B"):ColumnWidth = 20
ch-Worksheet:COLUMNS("C"):ColumnWidth = 15
ch-Worksheet:COLUMNS("D"):ColumnWidth = 15
ch-Worksheet:COLUMNS("E"):ColumnWidth = 15.
ASSIGN
ch-Worksheet:Range("A1:Z1"):FONT:Bold = TRUE
ch-Worksheet:Range("A1"):VALUE = "ItemProdPPN"
ch-Worksheet:Range("B1"):VALUE = "ItemSerial"
ch-Worksheet:Range("C1"):VALUE = "Date"
ch-Worksheet:Range("D1"):VALUE = "Station"
ch-Worksheet:Range("E1"):VALUE = "Time"
iRow = iRow + 1.
FOR EACH tt-prodqry NO-LOCK.
ASSIGN
cRow = STRING(iRow)
cCell = "A" + cRow
ch-Worksheet:Range(cCell):VALUE = tt-prodqry.prodppn
cCell = "B" + cRow
ch-Worksheet:Range(cCell):VALUE = (tt-prodqry.ItemSerial)
cCell = "C" + cRow
ch-Worksheet:Range(cCell):VALUE = tt-prodqry.prodndate
cCell = "D" + cRow
ch-Worksheet:Range(cCell):VALUE = tt-prodqry.station
cCell = "E" + cRow
ch-Worksheet:Range(cCell):VALUE = STRING (tt-prodqry.prodtime, "HH:MM:SS" )
iRow = iRow + 1.
END.
chExcelApplication:VISIBLE = TRUE.
SESSION:SET-WAIT-STATE ("").
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&UNDEFINE SELF-NAME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK wWin
/* *************************** Main Block *************************** */
/* Include custom Main Block code for SmartWindows. */
{src/adm2/windowmn.i}
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
/* ********************** Internal Procedures *********************** */
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE adm-create-objects wWin _ADM-CREATE-OBJECTS
PROCEDURE adm-create-objects :
/*------------------------------------------------------------------------------
Purpose: Create handles for all SmartObjects used in this procedure.
After SmartObjects are initialized, then SmartLinks are added.
Parameters: <none>
------------------------------------------------------------------------------*/
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE disable_UI wWin _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(wWin)
THEN DELETE WIDGET wWin.
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 wWin _DEFAULT-ENABLE
PROCEDURE enable_UI :
/*------------------------------------------------------------------------------
Purpose: ENABLE the User Interface
Parameters: <none>
Notes: Here we display/view/enable the widgets in the
user-interface. In addition, OPEN all queries
associated with each FRAME and BROWSE.
These statements here are based on the "Other
Settings" section of the widget Property Sheets.
------------------------------------------------------------------------------*/
DISPLAY ordnum
WITH FRAME fMain IN WINDOW wWin.
ENABLE ordnum BUTTON-1
WITH FRAME fMain IN WINDOW wWin.
{&OPEN-BROWSERS-IN-QUERY-fMain}
VIEW wWin.
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE exitObject wWin
PROCEDURE exitObject :
/*------------------------------------------------------------------------------
Purpose: Window-specific override of this procedure which destroys
its contents and itself.
Notes:
------------------------------------------------------------------------------*/
APPLY "CLOSE":U TO THIS-PROCEDURE.
RETURN.
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
I don't see a wait-for in there anywhere.
On Tue, Nov 24, 2009 at 5:03 PM, Tim Smith
Sorry. I searched my HD and found it is in src/adm2/windowmn.i
i went back through the code and in the block for the button there werent enough end statements to close it all off, it now works, as for why the button was esecuted straight away still eludes me.
smithtj wrote:
i went back through the code and in the block for the button there werent enough end statements to close it all off, it now works, as for why the button was esecuted straight away still eludes me.
Actually, you answered your own question.. Syntactically, the code was correct, because the AppBuilder expanded the code block until it found the necessary number of end statements, but because of this expansion, the 'button' code was executed at run time..