Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing a parameter to a VB2005 form

Status
Not open for further replies.

jpowe60

Programmer
Mar 4, 2009
35
0
0
US
I am a new VB2005 programmer...learning this ojt. i use a VFP application that passes a report file name to crystal, version 8.5 and 10. The statement that I used was
do form rptin_report with "report file name". I have created a vb2005 form to display a cr2008 report. when I hard code the reportname in the reportsoource field, the report get displayed no problem. What I need to do is to have this form accept any cr2008 report name based upon the report selection user is currently running. I have th following statement in VFP is run /N display_reports.exe I can't figure out two items though they are probably staring at me..the first is how do i include the reprot name after the .exe and 2)on the Vb side, where/how do I tell VB where to picked up the variable and process the report..

any comments/suggestions/pointing me to any documentation greatly appreciated

thank you in advance
 
I also use vfp,vba,and vbs
and ask a similar question some time back
thread707-1535260

This old world keeps spinning round - It's a wonder tall trees ain't layin' down
 
If I understand correctly, you wish to allow your user to browse for reports, loading their selected reports. Try the following code
Code:
        'Open File Dialog
        Dim ofd As New OpenFileDialog
        ofd.Filter = "Crystal Reports files (*.rpt)|*.rpt"
        ofd.ShowDialog()

        'Report Document
        If ofd.FileName <> "" Then
            Dim MyReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument
            MyReportDocument.Load(ofd.FileName)
            MyReportViewer.ReportSource = MyReportDocument
        End If

        ofd.Dispose()
        ofd = Nothing
 
thanks for getting back to me...I guess I did not fully explain what i want to do. What I need to do is to have a "skeleton" vb form that will display a cr2008 report based upon upon what applicaiton the user is currently using. For that to happen, I need to pass the Cr2008 report file name to this 'skeleton" vb2005 form ansd since I'm new to VB, I do not mknow how to set up the Vb code to accepts a variable being passed to it...

any suggestion greatly appreciated...
 
The easiest to code would be the following

Code:
Public ReportFileName As String

Sub LoadReport
  MyReportDocument.Load(ReportFileName)
End Sub

Code:
Dim SF As New SkeletonForm
SF.ReportFileName = "FileNameOfSomeReport"
SF.LoadReport
SF.ShowDialog()
 
thank you for getting back to me ...greatly appreciated..
 
Here is a real novice question...

how does one execute a vb.exe form to include the
file name being passed to the vb.exe...

as i said this is a true novice question...i know how tio do it using VFP but not VB...

thanks again
 
I'm not sure what you mean by your question. I've never worked with VFP, but from what I understand, it's a 4GL development environment. Meaning, it's used to develop a certain type of application--namely database applications. Visual Basic, on the other hand, is a general purpose programming language. Since you can do all sorts of things with it, and since applications don't need to have anything to do with databases or reports, the code involved to display a report is probably more involved than VFP.

That said, by the phrase how does one execute a vb.exe form to include the
file name being passed to the vb.exe...
if you are saying "how do i tell vb to execute a report based on the filename which was passed to the form," then that question depends on the reporting solution you are using. Crystal Reports has a different API than does the Microsoft Reporting Services/.rdl reporting solution.

That being said, the code I posted above demonstrates a Crystal example. In Crystal development, you create a ReportDocument object. You then load the ReportDocument. My example is loading the FileName from the OpenFileDialog I created, but you could put your filename variable in there. Next, you set your Crystal ReportViewer control's ReportSource equal to a valid ReportDocument as I have shown above.

Now, another way to interpret your question would be "How do I pass a command line argument to my Visual Basic application which when executed, uses that command line argument to display a specific report?" If that is your question, I would suggest you rethink your design process. If your design is to have the user go to the command line, navigate to your application's installation folder, type out MyApplication.exe followed by the name of a report, then that approach will be much more difficult from an end-user perspective than allowing the user to select a report from the GUI, using standard Windows dialogs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top