I have found
I do not develop with VB but with Centura. The call of the functions is the
same in the two language.
I give you a part of my Code for people who want to "use" Crystal Report
The source code use crpe32.dll
LIMITATION: The Code only accept String parameters.
What you can do with this source code :
* Use String Parameters
* Change Server/Database/User/Password (with subreport if you want)
* Change the query (where/Order)
Some comments can be in French ! Sorry, i have not the time to change them.
Youy will first find a function which is called from the preview and then
functions to drive CR8.0
Hope it will be Helpfull !!
Woodstock
! At the creation of the document (which serve to preview)
Function: OnCreateComplete
Local variables
Number: nXT
Number: nYT
Number: nXB
Number: nYB
!
Boolean: bTree
Boolean: bCanDrillDown
Boolean: bNavigationButtons
Boolean: bCancelButton
Boolean: bPrintButton
Boolean: bExportButton
Boolean: bZoomControl
Boolean: bCloseButton
Boolean: bProgressControls
Boolean: bSearchButton
Boolean: bPrintSetupButton
Boolean: bRefreshButton
Actions
If nModeImpression = CRYSTAL_PrintPreview
Call GetClientRect ( hWndForm, nXT, nYT, nXB, nYB )
Call fnInit( )
Call fnSetLogonDefaults ( NomServeur , NomDatabase , NomUser ,
NomPassword)
Set striReportFileName = AppDirectoryRapports || NomRPT
Call fnOpen( )
If nModeImpression = CRYSTAL_PrintPreview
Loop Gestion des flags
Set bTree = ( nFlags & CRYSTAL_Tree = CRYSTAL_Tree )
Set bCanDrillDown = ( nFlags & CRYSTAL_CanDrillDown =
CRYSTAL_CanDrillDown )
Set bNavigationButtons = ( nFlags & CRYSTAL_NavigationButtons =
CRYSTAL_NavigationButtons )
Set bCancelButton = ( nFlags & CRYSTAL_CancelButton =
CRYSTAL_CancelButton )
Set bPrintButton = ( nFlags & CRYSTAL_PrintButton =
CRYSTAL_PrintButton )
Set bExportButton = ( nFlags & CRYSTAL_ExportButton =
CRYSTAL_ExportButton )
Set bZoomControl = ( nFlags & CRYSTAL_ZoomControl =
CRYSTAL_ZoomControl )
Set bCloseButton = ( nFlags & CRYSTAL_CloseButton =
CRYSTAL_CloseButton )
Set bProgressControls = ( nFlags & CRYSTAL_ProgressControls =
CRYSTAL_ProgressControls )
Set bSearchButton = ( nFlags & CRYSTAL_SearchButton =
CRYSTAL_SearchButton )
Set bPrintSetupButton = ( nFlags & CRYSTAL_PrintSetupButton =
CRYSTAL_PrintSetupButton )
Set bRefreshButton = ( nFlags & CRYSTAL_RefreshButton =
CRYSTAL_RefreshButton )
Set bRefreshButton = FALSE
Break
! Preview
Call fnPrintPreview ( striReportFileName,stTitre, nXT, nYT, nXB, nYB,
WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_BORDER, hWndItem )
Call fnSetWindowOptions ( bTree, bCanDrillDown, bNavigationButtons,
bCancelButton, bPrintButton, bExportButton, bZoomControl, bCloseButton,
bProgressControls, bSearchButton, bPrintSetupButton, bRefreshButton )
Call PEZoomPreviewWindow( niJobNo, PE_ZOOM_SIZE_FIT_ONE_SIDE)
Call fnRefresh ( )
Call SalSetWindowText ( hWndForm, stTitre || ' - [ ' || NomRPT || ' ]')
Else
Call fnPrint ( NomRPT , NbCopies)
Call SalDestroyWindow( hWndForm )
The general functions
Form Window Class: clsfrmCrystalReport
Instance Variables
Window Handle: hWndReport
String: stReportName
Boolean: bOk
Number: niJobNo
Boolean: biOK
String: striServer
String: striDBName
String: striUser
String: striPassword
String: striReportFileName
Number: niJobNoSubreport[*]
Number: nSubreportHandle[*]
Number: nNbniJobNoSubreport
Functions
Function: OnSize
Description:
Returns
Parameters
Static Variables
Local variables
Number: nXT
Number: nYT
Number: nXB
Number: nYB
Actions
If hWndReport != hWndNULL and SalGetWindowState ( hWndReport ) !=
Window_Invalid
Call GetClientRect ( hWndForm, nXT, nYT, nXB, nYB )
Call SetWindowPos ( hWndReport, hWndNULL, nXT, nYT , nXB, nYB,
SWP_NOZORDER | SWP_NOCOPYBITS )
Function: fnDisplayError
Description: This function displays the error number and text if not
biOK. This prevents the need to constantly
test the boolean and call this function if TRUE
The default function is very useful during development
The Driver functions make a late bound call to this function so that a
dervided class or object w/functions
can replace this development function
Returns
Boolean:
Parameters
Static Variables
Local variables
Number: nErrorCode
Number: nTextHandle
Number: nTextLen
String: sError
Actions
If NOT biOK
Set nErrorCode = PEGetErrorCode( niJobNo )
Call PEGetErrorText( niJobNo, nTextHandle, nTextLen )
Call SalStrSetBufferLength( sError, nTextLen -1)
Call PEGetHandleString( nTextHandle, sError, nTextLen )
Call SalMessageBox( 'An error has occurred while printing your report.
Error Number: ' || SalNumberToStrX (nErrorCode,0) || ' ' || sError,
'Crystal Report Error', MB_Ok | MB_IconExclamation )
Return biOK
Function: fnGetNthReportParam
Description: Set a specific Parameter
Returns
String: stTemp
Parameters
Number: npParamNumber
Static Variables
Local variables
String: strName
String: strPrompt
String: strDefaultValue
Number: nDefaultValueSet
Number: nCurrentValueSet
String: strDummy
String: stTemp
String: strpParamValue
Number: npParamType
Actions
If biOK
Call SalStrSetBufferLength( strName,255)
Call SalStrSetBufferLength( strPrompt, 255 )
Call SalStrSetBufferLength( strDefaultValue, 255 )
Call SalStrSetBufferLength( strpParamValue, 255 )
Set nDefaultValueSet = FALSE
Set nCurrentValueSet = TRUE
! 1032 = struct size 4 Words and 4 Char 255
Set biOK = PEGetNthParameterField( niJobNo, npParamNumber, 1032,
npParamType, nDefaultValueSet, nCurrentValueSet
, strName,strDummy, strPrompt, strDummy, strDefaultValue, strDummy,
stTemp )
Return strName
Function: fnSetNthReportParam
Description: Set a specific Parameter
Returns
Boolean:
Parameters
Number: npParamNumber
Static Variables
Local variables
String: strName
String: strPrompt
String: strDefaultValue
Number: nDefaultValueSet
Number: nCurrentValueSet
String: strDummy
String: strpParamValue
Number: npParamType
String: stTemp
Actions
If biOK
Call SalStrSetBufferLength( strName,255)
Call SalStrSetBufferLength( strPrompt, 255 )
Call SalStrSetBufferLength( strDefaultValue, 255 )
Call SalStrSetBufferLength( strpParamValue, 255 )
Set nDefaultValueSet = FALSE
Set nCurrentValueSet = TRUE
! 1032 = struct size 4 Words and 4 Char 255
Set biOK = PEGetNthParameterField( niJobNo, npParamNumber, 1032,
npParamType, nDefaultValueSet, nCurrentValueSet
, strName,strDummy, strPrompt, strDummy, strDefaultValue, strDummy,
stTemp )
!
Call SalStrSetBufferLength( strName,255)
Call SalStrSetBufferLength( strPrompt, 255 )
Call SalStrSetBufferLength( strDefaultValue, 255 )
Call SalStrSetBufferLength( strpParamValue, 255 )
Set nDefaultValueSet = FALSE
Set nCurrentValueSet = TRUE
! 1032 = struct size 4 Words and 4 Char 255
If npParamType = PE_PF_STRING
Set biOK = PESetNthParameterField( niJobNo, npParamNumber, 1032,
npParamType, nDefaultValueSet, nCurrentValueSet
, strName,strDummy, strPrompt, strDummy, strDefaultValue, strDummy,
stCrystal )
Else If npParamType = PE_PF_NUMBER
Set stCrystal = SalNumberToStrX( nCrystal, 0 )
Set biOK = PESetNthParameterField( niJobNo, npParamNumber, 1032,
npParamType, nDefaultValueSet, nCurrentValueSet
, strName,strDummy, strPrompt, strDummy, strDefaultValue, strDummy,
stCrystal )
Else
Set stCrystal = DateToStrX( dtCrystal )
Set biOK = PESetNthParameterField( niJobNo, npParamNumber, 1032,
npParamType, nDefaultValueSet, nCurrentValueSet
, strName,strDummy, strPrompt, strDummy, strDefaultValue, strDummy,
stCrystal )
Return biOK
Function: fnInit
Description: Inits key class variables
Returns
Parameters
Static Variables
Local variables
Actions
Set biOK = TRUE ! Init OK Flag
Set niJobNo = NUMBER_Null
Function: fnSetLogonDefaults
Description: Call if you need to Set the Reports Logon Parameters
NOTE: strpServer for ODBC is the Data Source Name (DSN) as configured
using your ODBC adminstrator
Returns
Parameters
String: strpServer
String: strpDBName
String: strpUser
String: strpPassword
Static Variables
Local variables
Actions
Set striServer = strpServer
Set striDBName = strpDBName
Set striUser = strpUser
Set striPassword = strpPassword
! Prepare strings to be sent to DLL functions
Call SalStrSetBufferLength(striServer,127)
Call SalStrSetBufferLength(striDBName,127)
Call SalStrSetBufferLength(striUser,127)
Call SalStrSetBufferLength(striPassword,127)
Function: IsRptOpen
Description: If JobNo is NULL, attempts to Open the report. If that
fails, it returns FALSE
Returns
Boolean:
Parameters
Static Variables
Local variables
Actions
If niJobNo = NUMBER_Null AND biOK
Call fnOpen ()
Return biOK
Function: fnOpen
Description: Opens a report file.
Returns
Boolean:
Parameters
Static Variables
Local variables
Number: nNbSection
Number: nSectionCode
Number: nNbSubReport
Number: nIndex
Number: nIndex2
String: stName
Number: nNLinks
Number: nIsOnDemand
Number: nExternal
Number: nReImportOption
! Number: bLinkChanged
! Number: bReimport
Actions
If biOK
Set biOK = PEOpenEngine( )
Set
...
read more »