[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to open a Crystall Report XI with VBScript

Posted on 2007-08-08
2
Medium Priority
?
817 Views
Last Modified: 2013-11-05
We have an existing VBScript that use ocx to execute Crystal report 6 and export them to plain text format.  I did some research and found out that ocx is no longer used and it have been replaced with rdc.  Most of the sample code were related to VB.  Can anyone provide some sample VBScript  code on how to execute Crystal Report XI?
0
Comment
Question by:edmondwu
2 Comments
 
LVL 42

Accepted Solution

by:
frodoman earned 150 total points
ID: 19655020
0
 

Author Comment

by:edmondwu
ID: 19670693
Thanks for your help frodoman!
I finally able to export plain text crystal report 10 or XI with VBScript.
Option Explicit

WScript.Echo "START: " & Date & " " & Time
WScript.Echo ""

Dim crApp
Dim crRpt

Dim intI, dateDate, dateTime, strRunDate, strRunTime
Dim objArgs, strArgs, strParseArray, strArg_r, strArg_p, strArg_l, strArgErr
Dim strReportFileName, strPrintFileName, intPrintFileLinesPerPage, txtSelectClause


On Error Resume Next

Set objArgs = WScript.Arguments
Set crApp = WScript.CreateObject ("CrystalRuntime.Application")

If (Err.Number <> 0) Then
   WScript.Echo "ERROR: " & Err.Number & " - " & Err.Description
   WScript.Quit(1)
End If

'--------------------
' Declare your variables here (when run with no command-line switches)
' These are always superceded by command-line arguments.
'--------------------

dateDate = Date()
dateTime = Time()
strRunDate = Right("0" & Day(dateDate), 2) & " " & MonthName(Month(dateDate), True) & " " & Year(dateDate)
strRunTime = Hour(dateTime) & ":" & Right("0" & Minute(dateTime), 2) & ":" & Right("0" & Second(dateTime), 2)

'--------------------
' End of user variables
'--------------------

For intI = 0 to objArgs.Count - 1
   strArgs = strArgs & " " & objArgs(intI)
Next

If (intI > 0) Then
   strArgs = Right(strArgs,Len(strArgs)-1)
   WScript.Echo "Arguments on command line: [" & strArgs & "]"
   WScript.Echo ""
Else
   WScript.Echo "Arguments on command line: []"
   WScript.Echo ""
End If

If (objArgs.Count > 0) Then
   For intI = 0 to objArgs.Count - 1
      If (InStr(1,objArgs(intI),"-r:")) Then
         strParseArray = split(objArgs(intI),"-r:")
         strReportFileName = strParseArray(1)
         strArg_r = True
      ElseIf (InStr(1,objArgs(intI),"-p:")) Then
         strParseArray = split(objArgs(intI),"-p:")
         strPrintFileName = strParseArray(1)
         strArg_p = True
      ElseIf (InStr(1,objArgs(intI),"-l:")) Then
         strParseArray = split(objArgs(intI),"-l:")
         intPrintFileLinesPerPage = strParseArray(1)
         strArg_l = True
      Else
         strArgErr = True
      End If
   Next
End If

If (strArg_r <> True or strArg_p <> True or strArg_l <> True or strArgErr = True) Then
   WScript.Echo "Usage: biCRExport.vbs [ -r:<ReportFileName> ] [ -p:<PrintFileName> ] [ -l:<PrintFileLinesPerPage> ]"
   WScript.Echo ""
   WScript.Echo "r <ReportFileName> - required, the filename of the report to be printed."
   WScript.Echo "p <PrintFileName> - required, the filename for output when printing to file."
   WScript.Echo "l <PrintFileLinesPerPage> - required, lines per page for paginated text export."
   WScript.Quit(1)
End If

ConfirmFileExists(strReportFileName)

Set crRpt = crApp.OpenReport(strReportFileName)

crRpt.ExportOptions.DestinationType = 1 'crEDTDiskFile
crRpt.ExportOptions.DiskFileName = strPrintFileName 'The filename for output when printing to file.
crRpt.ExportOptions.FormatType = 10 'crEFTPaginatedText 'The type of file created when printing to file.
crRpt.ExportOptions.NumberOfLinesPerPage = intPrintFileLinesPerPage 'Lines per page for paginated text export.

If (Err.Number = 0) Then
   crRpt.Export False 'Set this property to 1 to print the report.
End If

If (Err.Number <> 0) Then
   WScript.Echo "ERROR: " & Err.Number & " - " & Err.Description
   WScript.Echo ""
End If

Set objArgs = Nothing
Set crRpt = Nothing

WScript.Echo "FINISH: " & Date & " " & Time

WScript.Quit(Err.Number)

Function ConfirmFileExists(strFileName)

   'PURPOSE : Confirm that a file exists.
   'REQUIRES: The file name including the full path.
   'PROMISE : Returns a boolean True if the file exists.

   Dim objFileSystem

   Set objFileSystem = WScript.CreateObject("Scripting.FileSystemObject")

   If (objFileSystem.FileExists(strFileName)) Then
      ConfirmFileExists = True
   Else
      WScript.Echo "ERROR: File does not exist: " & strFileName
      WScript.Quit(1)
   End If

   Set objFileSystem = Nothing

End Function
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question