Tuesday, November 25, 2008

Get data from Excel via the clipboard

OLEObject excel

Integer li_RetValue, li_rtn
Boolean lb_sheet_rtn
Long ll_cnt

excel = create OLEObject
li_rtn = excel.ConnectToNewObject("excel.application")
IF li_rtn <> 0 THEN
MessageBox('Excel erro','can not run Excel Program')
DESTROY excel
RETURN 0
END IF
excel.WorkBooks.Open( "c:\mysheet.xls" )
excel.Application.Visible = false
excel.windowstate = 2 // 1 : Normal, 2 : Minimize, 3 : Maximize
lb_sheet_rtn = excel.worksheets(1).Activate
excel.Worksheets(1).Range("A1:E5000").Copy // copy to clipboard
ll_cnt = dw_1.importclipboard()
IF ll_cnt <<= 1 THEN
Messagebox("Inf", "Could not find .")
END IF
excel.Worksheets(1).Range("A10000:A10000").Copy //reset clipboard
excel.Application.Quit
excel.DisConnectObject()
DESTROY excel

Monday, November 24, 2008

Scroll 2 datawindows in sync

[ScrollVertical event of dw_1]
dw_2.Object.datawindow.verticalscrollposition = scrollpos

Detect if a row is new

dwitemstatus rowstatus
IF dw.GetRow() > 0 THEN
rowstatus = dw.GetItemStatus( dw.GetRow(), 0, Primary! )
IF rowstatus = New! OR rowstatus = NewModified! THEN
// new row
ELSE
// not new
END IF
END IF

Display only distinct rows

First you need to Sort() the datawindow based on the columns that need to be distinct. After you apply a Filter(), to filter out the non-distinct rows.
For example, we have a datawindow with a column named prod_id and we want to display only one row for each prod_id.
First we turn off the datawindow redraw function to speed up the operation

dw_1.setredraw(false)
Sort the rows based on the prod_id column
dw_1.setsort("prod_id a")
dw_1.sort()
Define the appropriate Filter
dw_1.SetFilter("IsNull(prod_id[-1]) OR prod_id[-1] <> prod_id")
dw_1.filter()
Finally turn back on the datawindow redraw
dw_1.setredraw(true)

Make the ENTER key act as TAB key

First, define a user event to correspond with the pbm_dwnprocessenter event on a datawindow. Then in that event :
Send(Handle(this),256,9,Long(0,0))
RETURN 1

Memory usage with PB7 and MS SQL direct driver

The memory used on the client is very large during a connection and on disconnect it comes back down again.
The fix is to put something in the DBParm property of the SQLCA object. Something like "Application='MyApp'" or whatever. In the development environment, edit the connection properties and make sure something is in the Application Name or Workstation Name on the Network tab.

Display PDF into a Window

Insert the "Adobe Acrobat ActiveX control" OLE control on the window.
Then to load a document from Powerscript
ole_1.object.LoadFile("C:\realhowto-pdf")
With a tool to explore the pdf.ocx, there are more functions :
function LoadFile(none fileName: WideString): WordBool [dispid $00000002]; stdcall;
procedure setShowToolbar(none On: WordBool) [dispid $00000003]; stdcall;
procedure gotoFirstPage [dispid $00000004]; stdcall;
procedure gotoLastPage [dispid $00000005]; stdcall;
procedure gotoNextPage [dispid $00000006]; stdcall;
procedure gotoPreviousPage [dispid $00000007]; stdcall;
procedure setCurrentPage(none n: Integer) [dispid $00000008]; stdcall;
procedure goForwardStack [dispid $00000009]; stdcall;
procedure goBackwardStack [dispid $0000000A]; stdcall;
procedure setPageMode(none pageMode: WideString) [dispid $0000000B]; stdcall;
procedure setLayoutMode(none layoutMode: WideString) [dispid $0000000C]; stdcall;
procedure setNamedDest(none namedDest: WideString) [dispid $0000000D]; stdcall;
procedure Print [dispid $0000000E]; stdcall;
procedure printWithDialog [dispid $0000000F]; stdcall;
procedure setZoom(none percent: Single) [dispid $00000010]; stdcall;
procedure setZoomScroll(none percent, left, top: Single) [dispid $00000011]; stdcall;
procedure setView(none viewMode: WideString) [dispid $00000012]; stdcall;
procedure setViewScroll(none viewMode: WideString; none offset: Single) [dispid $00000013]; stdcall;
procedure setViewRect(none left, top, width, height: Single) [dispid $00000014]; stdcall;
procedure printPages(none from, to: Integer) [dispid $00000015]; stdcall;
procedure printPagesFit(none from, to: Integer; none shrinkToFit: WordBool) [dispid $00000016]; stdcall;
procedure printAll [dispid $00000017]; stdcall;
procedure printAllFit(none shrinkToFit: WordBool) [dispid $00000018]; stdcall;
procedure setShowScrollbars(none On: WordBool) [dispid $00000019]; stdcall;
procedure AboutBox [dispid $FFFFFDD8]; stdcall;
But there is no documentation about them. You can download a free SDK (you need to register) but I believe that you need the Acrobat package to fully use it.
http://partners.adobe.com/asn/acrobat/download.jsp#fullinstall
Custom Search