I find myself with a lot of code (sub procedures) similar to the one below, which I know is not good. I think if I can be shown how this should be handled in an OOP world I can figure out how to do some of the other stuff in my applications OOP like (I am still trying to make the transition from Event driven programming to OOP).
For instance, say I have two buttons to open two different reports. I want to eliminate the redundant code and only put the report name (the only variable) behind the button.
I know this is not a very pratical way to handle opening multiple reports but I am only interested in getting the code into an OOP model.
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click CrystalReportViewer1.ReportSource = _ "C:\testreport_Number1.rpt" CrystalReportViewer1.RefreshReport() CrystalReportViewer1.Show() End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click CrystalReportViewer1.ReportSource = _ "C:\testreport_Number2.rpt" CrystalReportViewer1.RefreshReport() CrystalReportViewer1.Show() End Sub




Reply With Quote