CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Crystal Reports

  1. #1
    Guest

    Crystal Reports

    I'm creating an application that lists all the available reports in a file
    list box. It only
    lists the report name. They can double-click on a report and run it.

    I would like to be able to display the report title when they single-click
    the report.
    Does anyone know how to pull the title from the file. When I go through
    file manager
    and right-click the file it lists the title in the summary information.

    I've tried using the filesystemobject in Visual Basic but retrieving the
    title was not
    available to retrieve.

    Thanks for your help.



  2. #2
    Join Date
    Jun 1999
    Posts
    5

    Re: Crystal Reports

    First add the Crystal Report's Global32.BAS to your project. It is compressed on your disk if you can't find it.

    Create a class module named clsCrystal. Looks like this:

    private result as Integer
    private JobNum as Integer
    private pReportFileName as string
    private Const pModule as string = "clsCrystal"
    '----------------------------------------------------------------------------------------
    private Sub Class_Initialize()
    result = PEOpenEngine()
    If result = 0 then
    MsgBox "Could not start the print engine. Execution must halt.", vbCritical, "Serious error"
    End If
    End Sub
    '----------------------------------------------------------------------------------------
    public property get ReportFileName() as string
    ReportFileName = pReportFileName
    End property

    '----------------------------------------------------------------------------------------
    public property let ReportFileName(tmp as string)
    If JobNum <> 0 then
    PEClosePrintJob JobNum
    JobNum = 0
    pReportFileName = ""
    End If
    If tmp <> "" then
    JobNum = PEOpenPrintJob(tmp)
    ErrorTrap "ReportFileName"
    pReportFileName = tmp
    End If
    End property
    '----------------------------------------------------------------------------------------
    public Sub CloseCR()
    If JobNum <> 0 then
    PEClosePrintJob JobNum
    JobNum = 0
    pReportFileName = ""
    End If
    End Sub

    '----------------------------------------------------------------------------------------
    public property get ReportTitle() as string
    Dim grtResult as Long
    Dim grtTitleHandle as Long
    Dim grtTitleLength as Integer
    Dim grtReportTitle as string

    grtResult = PEGetReportTitle(JobNum, grtTitleHandle, grtTitleLength)
    ErrorTrap "ReportTitle"

    ' Preload the ReportTitle with enough space for the title
    grtReportTitle = string$(grtTitleLength, 0)

    ' get the title string itself
    grtResult = PEGetHandleString(grtTitleHandle, grtReportTitle, grtTitleLength)
    ErrorTrap "GetHandleString for ReportTitle in FormatOptions"

    ' Load the title onto the function
    ReportTitle = NTrim(grtReportTitle)
    End property
    '----------------------------------------------------------------------------------------
    private Sub ErrorTrap(etSource as string)
    Dim etResult as Long
    Dim etErrorcode as Long
    Dim etTextHandle as Long
    Dim etTextLength as Integer
    Dim etErrorText as string
    Dim etJobNum as Long


    ' Check for any error codes
    etErrorcode = PEGetErrorCode(JobNum)
    If etErrorcode <> 0 then
    ' If there is an error code, find out what it means

    'Err.Raise etErrorcode + 20000
    etResult = PEGetErrorText(JobNum, etTextHandle, etTextLength)
    If etResult = 0 then
    ' If getting the text failed, say so
    etErrorText = "error in ErrorTrap routine"
    else
    ' get the text from the handle
    etErrorText = string(etTextLength, 0)
    etResult = PEGetHandleString(etTextHandle, etErrorText, etTextLength)
    etErrorText = Trim(etErrorText)
    etErrorText = Left(etErrorText, len(etErrorText) - 1)
    End If

    Err.Raise etErrorcode + 20000, etSource, etErrorText
    End If

    ' Be sure to add error handling in this proceedure...Wade Balzer

    End Sub


    '----------------------------------------------------------------------------------------
    private Sub Class_Terminate()
    If JobNum <> 0 then
    PEClosePrintJob JobNum
    JobNum = 0
    pReportFileName = ""
    End If
    PECloseEngine
    End Sub
    '----------------------------------------------------------------------------------------
    private Function NTrim(strFixedtoString as string) as string
    Dim tmpPos as Integer
    tmpPos = InStr(strFixedtoString, Chr(0))
    If tmpPos = 0 then tmpPos = len(strFixedtoString) + 1
    NTrim = Left(strFixedtoString, tmpPos - 1)
    End Function




    Somewhere in your code you will have to:


    Dim cr as new clsCrystal

    cr.ReportFilename = "C:\REPORTS\TEST.RPT" 'Initialize the class
    ReportTitle = cr.ReportTitle
    cr.CRClose 'Close the Crystal Engine





    Hope this helps. If you need a fuller class, I have developed one.

    Wade Balzer


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured