Schultz’s PowerBuilder Notes

Changing an Object’s Ancestor


I was once in a code review and I noted that the custom object that was built should be inherited from n_base so it can inherit the constants SUCCESS, FAILURE and NO_ACTION.

Continue reading

July 14, 2008 Posted by | 1. PowerBuilder General | , , , , , | Leave a comment

Exporting Data


How do I write the contents of a DataWindow or datastore to an ASCII file?

Dw_1.SaveAs(“<file name>”, TEXT!, false) // Last parameter suppresses column headings.

May 25, 2008 Posted by | Datawindow PowerScript | , , , , | Leave a comment

Migrating PB9 Objects to PB7


You may find yourself working in PB 7 and wanting to use a DataWindow developed in PB 9.  Some objects are easier than others.

 DataWindows

Datawindows are addressed specifically in the previous post.  Take a look there

Windows and User Objects

Try opeingi up the  PB 9 version in PB 7.   If this works, Just save it and you are good to go.   If blows up,  here are several  possible causes:

  • An invalid global variable is being referenced
  • A non-standard variable is of a datatype which was not included found in the search path
  • A non-standard variable refers to an object which has not yet been migrated to PB 7

You can clean up the code by editing the .srw export file with a text editor and commenting out the offending references.  When you import the file, make sure the PB 9 version is not in your library path, otherwise the import will fail.  You will not get a helpful error message or PowerBuilder will crash.

April 17, 2008 Posted by | 1. PowerBuilder General, PowerBuilder Versions | , , , , , , , , , , | Leave a comment

Migrating a DataWindow from PB 9 Back to PB 7


You may find yourself working in PB 7 and wanting to use a DataWindow developed in PB 9. This can be done if you export the PB 9 code (export may be done in PB 7), update the srd file, and then import it to your PB7 PBL.

PB 9 SRD file

$PBExportHeader$d_cycl_validation.srd
release 9;
datawindow(units=0 timer_interval=0 color=67108864 processing=0 HTMLDW=no print.printername="" print.documentname="" print.orientation = 0 print.margin.left = 110 print.margin.right = 110 print.margin.top = 96 print.margin.bottom = 96 print.paper.source = 0 print.paper.size = 0 print.canusedefaultprinter=yes print.prompt=no print.buttons=no print.preview.buttons=no print.cliptext=no print.overrideprintjob=no print.collate=yes hidegrayline=no )
summary(height=0 color="536870912" )
footer(height=0 color="536870912" )
detail(height=68 color="536870912" )
table(column=(type=char(10) updatewhereclause=yes name=cycl_rtg_id dbname="CYCL_RTG_ID" )
 column=(type=char(32) updatewhereclause=yes name=descr dbname="DESCR" )
 retrieve="SELECT  CRM.CYCL_RTG_ID,
        CRM.DESCR
FROM    QUAD0062..CYCL_RTG_MSTR CRM
WHERE   CRM.CYCL_RTG_ID = :CYCLE_ID
AND     CRM.PDCT_CD = 'M'
AND     CRM.RTG_CLA <> 'D'"
column(band=detail id=2 alignment="0" tabsequence=32766 border="5" color="0" x="347" y="4" height="56" width="1024" format="[general]" html.valueishtml="0"  name=descr visible="1" edit.limit=0 edit.case=any edit.autoselect=yes edit.imemode=0  font.face="Arial" font.height="-8" font.weight="400"  font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="553648127" )
text(band=detail alignment="0" text="Description:" border="0" color="0" x="9" y="4" height="56" width="311" html.valueishtml="0"  name=t_1 visible="1"  font.face="Arial" font.height="-8" font.weight="700"  font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="553648127" )
htmltable(border="1" )
htmlgen(clientevents="1" clientvalidation="1" clientcomputedfields="1" clientformatting="0" clientscriptable="0" generatejavascript="1" encodeselflinkargs="1" netscapelayers="0" )
export.xml(headgroups="1" includewhitespace="0" metadatatype=0 savemetadata=0 )
import.xml()
export.pdf(method=0 distill.custompostscript="0" xslfop.print="0" )

Changes Needed for Converting Sample SRD File to PB 7

Note, lines 18 -21 refer to the last 4 lines of your SRD file.

  • Line 2
    • Change “Release 9” to “Release 7
  • Line 3
    • Delete “print.printername=””
    • Delete “print.canusedefaultprinter=yes
    • Delete “print.cliptext=no print.overrideprintjob=no print.collate=yes hidegrayline=no” (end of the line)
  • Line 18
    • At the end of the line, delete “encodeselflinkargs=”1″ netscapelayers=”0″
  • Line 19-21
    • Delete these lines

PB 7 SRD file

The final SRD file is now ready to be imported into PB 7. It looks like the following:

 $PBExportHeader$d_cycl_validation.srd
 release 7;
 datawindow(units=0 timer_interval=0 color=67108864 processing=0 HTMLDW=no print.documentname="" print.orientation = 0 print.margin.left = 110 print.margin.right = 110 print.margin.top = 96 print.margin.bottom = 96 print.paper.source = 0 print.paper.size = 0 print.prompt=no print.buttons=no print.preview.buttons=no )
 summary(height=0 color="536870912" )
 footer(height=0 color="536870912" )
 detail(height=68 color="536870912" )
 table(column=(type=char(10) updatewhereclause=yes name=cycl_rtg_id dbname="CYCL_RTG_ID" )
  column=(type=char(32) updatewhereclause=yes name=descr dbname="DESCR" )
  retrieve="SELECT  CRM.CYCL_RTG_ID,
         CRM.DESCR
 FROM    QUAD0062..CYCL_RTG_MSTR CRM
 WHERE   CRM.CYCL_RTG_ID = :CYCLE_ID
 AND     CRM.PDCT_CD = 'M'
 AND     CRM.RTG_CLA <> 'D' " arguments=(("CYCLE_ID", string)) )

April 16, 2008 Posted by | 2. Datawindows, PowerBuilder Versions | , , , , , , , , , , | Leave a comment

Adding “Export to Excel” Menu item


Add a menu item under FUNCTIONS which exports a datawindow to excel. This example assumes PFC is being used.

M_frame

Add the item Functions > Export to Excel

Script

of_SendMessage(‘ue_export’)

Properties:

Enabled = FALSE

w_sheet_lm

Your main sheet ancestor

  • Instance Variables

Protected:

u_dw idw_export

  • ue_export

//////////////////////////////////////////////////////////////////////////////
// Event: w_sheet_lm:ue_export
//
// Description: export the registered datawindow (idw_export) to excel
//
//////////////////////////////////////////////////////////////////////////////

if IsValid(idw_export) then
. idw_export.SaveAs(“”, Excel5!, TRUE)
end if

How to use

  1. In the Activate Event of the sheet, enable the menu item EXPORT
  2. In the Deactivate Event of the sheet, disable the menu item EXPORT
  3. In the window pfc_preopen event, associate the datawindow you wish to export to idw_export
  4. If you want to do something trickier, for example, you want to allow the user to select one of several different datawindows to export, override the sheet’s UE_EXPORT event.

April 15, 2008 Posted by | Menus | , , | Leave a comment

   

Follow

Get every new post delivered to your Inbox.