Passing parameters in VB.Net that converts Crystal Report to pdf

I have a VB.NET windows app, that has a button goes out and converts CR to PDF, and I don't view it.  This works fine.  I am wanting now to have a parameter passed into this CR pulling out of a table, passed to my report then generated into a pdf.  Say that the field in the table is strVariable.

Here is my code that does the conversion, could someone please help me and show me where I would put in this passing of a parameter.  Like where to put it in my VB.NET code?  Thanks so much...

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Place the following name spaces at the top of the code page
        Dim fileList() As String = System.IO.Directory.GetFiles("c:\inetpub\wwwroot\MCNETWebSite\IT_Work\")

        For Each fileSource As String In fileList
            If Strings.Right(fileSource, 4) = ".rpt" Then
                'Crystal Export Code Here
                Dim CrReport As New ReportDocument
                CrReport.Load(fileSource, OpenReportMethod.OpenReportByDefault)

                Dim CrExportOptions As ExportOptions
                Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions
                Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions

                ' Set the destination path and file name
                ' 41 is the spot where I need to get file name 41 (34 old)
                Dim mid As String
                mid = Strings.Mid(fileSource, 41)

                ' Gets the length of the filename
                Dim LengthObjName As String
                LengthObjName = Strings.Len(mid)

                ' Gets charactor to start at for taking out of the .rpt
                Dim LengthFrom_rpt As String
                LengthObjName = CInt(LengthObjName - 4)

                ' Gets the actual file name minus the .rpt extension
                Dim strVarName As String
                strVarName = Strings.Left(mid, LengthObjName)

                'Getobj = Microsoft.VisualBasic.GetObject(fileSource)
                Dim pdf_path As String
                pdf_path = "c:\CR_Convert_to_PDF\" & strVarName & ".pdf"
                CrDiskFileDestinationOptions.DiskFileName = pdf_path

                'Specify a page range (optional)
                CrFormatTypeOptions.FirstPageNumber = 1
                CrFormatTypeOptions.LastPageNumber = 3
                CrFormatTypeOptions.UsePageRange = True
               
                'Set export options
                CrExportOptions = CrReport.ExportOptions

                With CrExportOptions
                    'Set the destination to a disk file
                    .ExportDestinationType = ExportDestinationType.DiskFile
                    'Set the format to PDF
                    .ExportFormatType = ExportFormatType.PortableDocFormat
                    'Set the destination options to DiskFileDestinationOptions object
                    .DestinationOptions = CrDiskFileDestinationOptions
                    .FormatOptions = CrFormatTypeOptions
                End With

                ' Trap any errors that occur on export
                Try
                    'Export the report
                    CrReport.Export()
                    MessageBox.Show("PDF File Generated from " & fileSource & " into location: " & pdf_path)
                Catch err As Exception
                    MessageBox.Show(err.ToString())
                End Try

            End If
        Next
        MessageBox.Show("All pdf files created successfully.")

    End Sub
LVL 1
vikingg97Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mlmccCommented:
You put the code somewhere before you call the export routine.

I would put them after you set the export options.

mlmcc
0
vikingg97Author Commented:
I forgot to put in my question how to to get this variable out of a table and to put it into a parameter within the CR?  

Say if the field in the table is strVariable?

I have looked around but haven't found any definitive answers.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

ebolekCommented:
So you want to set  aparameter in runtime and then export the final diocument to pdf right? I have c3 code for you. Can you convert it to vb.net
0
vikingg97Author Commented:
I can always try to convert it I suppose ebolek.  Remember this is not a web application.  This is a VB.NET windows application.  
0
ebolekCommented:
That is fine. Workd for windows.

Here is the code.

internal static void CreateParameter(ref ReportDocument report, string ParameterName, object value)
            {
                  ParameterDiscreteValue  ParameterDiscreteValue;
                  ParameterValues  ParameterValues;
                  ParameterFieldDefinition param = report.DataDefinition.ParameterFields[ParameterName];
                  ParameterValues = new CrystalDecisions.Shared.ParameterValues();
                  ParameterDiscreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue();      
                  ParameterDiscreteValue.Value = value;      
                  ParameterValues.Add(ParameterDiscreteValue);
                  param.CurrentValues.Clear();
                  param.DefaultValues.Clear();  
                  param.ApplyCurrentValues(ParameterValues);
            }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ebolekCommented:
Glad I could help

Regards
Emre
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.