Archive for computer

Changing Report Objects Run Time

Posted in Coding with tags , , , , , on 28 February 2008 by harisanto

Creating and using a Crystal Reports report in a VB.Net project using SQL Server is a multi-step process. This lesson takes you through the steps using one approach that is suitable for when the report is based on a stored procedure (SP) that generates dynamic data based on either current DB values or parameters passed to the underlying SP. There are other approaches but you will have to investigate them on your own if you are interested.

The steps are:

  1. Establish the SP that will supply data for the report
  2. Establish a VB ‘model’ for the data in the report using a VB Dataset.XSD file based on your SP results.
  3. Create the report and link it to the Dataset (DS) table created above.
  4. Design the report using the visual tools in Crystal Reports (CR).
  5. Create a CR report viewer on a form(s) along with whatever other interface elements you need to have (e.g., to provide SP parameter input, execute the report loading, etc.)
  6. Write code to execute your SP and store the result into a DataSet on the form creating the CR report viewer
  7. Create a report object in code and set appropriate values, including the location of the DataSet containing the report’s actual data. (Remember, the Dataset.XSD file referenced in Step 2 only contains a model of the data.)
  8. Write code to pass the report object to the report viewer as the report source. This causes the report to become visible in the viewer.

Sometimes it is useful to be able to change the values of text objects on a report in code. This is done in the SQL Database Documenter program (see the lesson on documenting SQL Server databases). You can change report text objects by creating a text object reference in your code and then setting properties. This must take place before the report object is passed to the report viewer control.

Note: objReport must have been declared and instantiated previously as illustrated in the “R” lines in the code listing above. Assignments such as the one below must take place before the report object (objReport) is passed to the report viewer.  

Steps to do:

  1. Design the report using the visual tools in Crystal Reports (CR) and add Text Object, give it name eg Text1.
  2. Create a CR report viewer on a form(s).
  3. Take a looks on this code:

Dim rptTxtGroup As CrystalDecisions.CrystalReports.Engine.TextObject

rptTxtGroup = report.ReportDefinition.ReportObjects.Item(“Text1″)
rptTxtGroup.Text = “Halooo”

Yes, just this… very simple ist’n … he he he. Btw, you can use it in all object excepting OLE Object eg Picture or Blob mode.

Use the My Objects to Program Common Tasks

Posted in Coding, VB.NET with tags , , , , , on 27 February 2008 by harisanto

The new My objects provide easy access to various features that developers often need but don’t necessarily know where to find in the sprawling .NET class library. Essentially, the My objects offer one-stop shopping, with access to everything from the Windows registry to the current network connection. Best of all, the My object hierarchy is organized according to use and is easy to navigate using Visual Studio IntelliSense.

Tired of hunting through the extensive . NET class library in search of what you need? With the new My objects, you can quickly find some of the most useful features . NET has to offer.

There are seven first-level My objects. Out of these, three core objects centralize functionality from the .NET Framework and provide computer information. These include:

My.Computer
This object provides information about the current computer, including its network connection, the mouse and keyboard state, the printer and screen, and the clock. You can also use this object as a jumping-off point to play a sound, find a file, access the registry, or use the Windows clipboard.

My.Application
This object provides information about the current application and its context, including the assembly and its version, the folder where the application is running, the culture, and the command-line arguments that were used to start the application. You can also use this object to log an application event.

My.User
This object provides information about the current user. You can use this object to check the user’s Windows account and test what groups the user is a member of.
Along with these three objects, there are another two objects that provide default instances. Default instances are objects that .NET creates automatically for certain types of classes defined in your application. They include:

My.Forms
This object provides a default instance of each Windows form in your application. You can use this object to communicate between forms without needing to track form references in another class.

My.WebServices
This object provides a default proxy-class instance for every web service. For example, if your project uses two web references, you can access a ready-made proxy class for each one through this object.

Finally, there are two other My objects that provide easy access to the configuration settings and resources:

My.Settings
This object allows you to retrieve custom settings from your application’s XML configuration file.

My.Resources
This object allows you to retrieve resourcesblocks of binary or text data that are compiled into your application assembly. Resources are typically used to store localized strings, images, and audio files.

Some of the My classes are defined in the Microsoft.VisualBasic.MyServices namespace, while others, such as the classes used for the My.Settings and My.Resources objects, are created dynamically by Visual Studio 2005 when you modify application settings and add resources to the current project.

Warning: Note that the My objects are influenced by the project type. For example, when creating a web or console application, you won’t be able to use My.Forms.