Traditional Culture Encyclopedia - Weather inquiry - How to write weather forecast program with VB.net Visual Basic project?

How to write weather forecast program with VB.net Visual Basic project?

Overview of Visual Basic General Report Design

This paper summarizes the method of designing reports with vb. As we all know, there are roughly two options for making reports under VB platform: using the data report control provided by VB and using the third-party software. Among them, the famous third-party software is MS Excel and CrystalReporter of Seagate Company. Three schemes are discussed in detail below.

1. Data reporting control

1. 1 Usage of data report control

Because it is a control that comes with VB, it is relatively convenient to use. How to use it is: First, select the "Add Data Report" option under the "Project" menu, so that the data report control is selected to enter the application.

Data binding is mostly used in the use of data reports, that is, the control is bound to the data table of the database, so that the design of the report can be easily completed without writing code. To use data binding, you must specify a data source. The data source here is not data control, but data environment. Select the Add Data Environment option under the Project menu to add the data environment to the application. Data environment has two important attributes: connection and command attributes. The former is to connect to the specified database, and the latter is to connect to the specified data table. Once these two properties are set successfully, the data environment can be used as a data source. Just set the DataSource property of the data report to the previous data environment object and the DataMember to the Command object of the data environment object.

1.2 data report control interface element

After the data binding of the data report control is completed, the report generation and display can be directly controlled. First of all, be familiar with the display interface of data report controls:

The data report control1* * consists of five areas, namely report header, page header, detail area, page footer and report footer. The report title and report footnote are used at the top and bottom of the whole report respectively. They will appear on every page of the whole report, and you can also put some fixed words such as report name and time. Headers and footnotes can only appear at the top and bottom of the current page, that is to say, they can only appear on the current page and not on other pages. You can place some quantities that change with the page, such as page numbers; The detail area is the area for actual display, and it is the area we are most concerned about. By placing display controls in this area, you can control the actual display output of the report. Here's how to place a text box control. In fact, in the case of binding, you only need to set its DataMember and Datafield. The former is used to specify the data table, which can be set as the command object of the previous data environment object, and the latter is the specified data segment, that is, the specified field of the binding database. This way, you can display the report without writing any code.

1.3 printing function of data report control

For report printing, you can directly use the printing function of data reports, that is, you can print simple reports. But in order to realize more complex printing function, it can also be carried out through program control. This is just a realization idea: firstly, you need to make a button control to display the "print settings" window, through which users can set the relevant parameters of printing, and then use the printer object embedded in VB in the sub-module to realize real printing, which can locate the current position of printing and control the parameters such as printing font, so that the printing function similar to that in word can be realized by combining the "print settings" window.

2.MS Excel

Speaking of report design application, Microsoft Excel is unique. MS Excel is an application for designing tables and reports. It has excellent grid control and macro code customization functions. So if you can design your own application with Excel, your application should be perfect, because Excel provides a perfect solution for editing and printing functions, so what your application needs to do is to realize the communication between the program and Excel.

In fact, you can use VBscript to connect VB and Excel. Here is a brief introduction to the development of Excel-based programming ideas under VB.

There are five objects to handle Excel in VB: application object, workbook object, worksheet object, range object and cell object. Their functions are as follows:

Application-Used to refer to the entire application.

Workbook- Represents a workbook object.

WorkSheet-Represents a worksheet object. Note that a workbook can contain multiple worksheets, just like a frame window and a view in multiple documents.

Range-represents a range object in the worksheet, or only a cell in special cases.

A cell object that represents a specific worksheet. This object is the most commonly used.

Knowing the application scope of the above five objects is very simple to use, but before using these objects, you need to declare them first. The method is to select "Microsoft Excel9.0 Object Library" under the "Reference" dialog box of the Project, so as to introduce the whole Excel object library into the program.

Let's take an example. Its function is to open a workbook.

The function OpenBook(strFilePath is a string) is a boolean value.

The process checks whether the workbook

The specified in the strFilePath parameter is open.

If it is open, the workbook is activated. If so

It's not open. The program opens it.

Display wkbCurrent as Excel. exercise book

Dim strBookName as a string

Go to OpenBook_Err when an error occurs.

Determines the name portion of the strFilePath parameter.

strBookName = NameFromPath(strfile path)

If Len(strBookName) = 0, the function exits.

If the workbook. Count & gt So 0

For each workflow in the workbook

If UCase $(wkbccurrent. Name) = UCase$(strBookName) Then

wkbCurrent。 Make active

Exit function

If ... it will be over.

ABC current next week

If ... it will be over.

Workbooks. Open strBookName

OpenBook = True

OpenBook_End:

Exit function

OpenBook_Err:

OpenBook = False

Resume open Book_End

End function

3. Crystal Report (Crystal Report)

As an excellent report software, Crystal Report is the most widely used scheme in practical application. This section mainly introduces the customization and display of crystal report and the realization of printing function.

First of all, distinguish between crystal report plug-ins and crystal report controls. The former is mainly used to create report templates, while the latter is mainly used to display and print reports in programs. The division of labor between them determines their different functions in the program.

Crystal Reports plug-ins can download the latest test version from Seagate official website.

3. Use of1Crystal Report Plug-in

Select the Report Designer option in the Plug-in menu, and VB will execute the Crystal Reports Pro plug-in application. Select the "New Report" icon in Crystal Reports Pro, and you can select 8 standard templates and a custom template to start the report project.

The use of the whole crystal report is very similar to the use of the data report in the first part. First, you need to select a data source (database) for the report, and then you can add, delete, modify fields and group records in the report. You can use Crystal Report to create many customized reports. Because Crystal Reports plug-in is a powerful report design software, I won't explain them here. If you are interested, you can refer to the help document that comes with the program.

3.2 background knowledge of crystal report control

Crystal Reports Pro also provides a report generation module, which can connect and access VB applications. VB programmers can add complex report generation and output functions to applications without spending a lot of time writing their own codes.

Crystal Reports engine is a dynamic link library, which can be accessed by applications and has the same powerful report output function as Crystal Reports. The application accesses the engine through the Crystal Reports ActiveX control. When recompiling, the application is linked with the report engine to add the function of generating reports for the application.

When a program uses the Crystal Reports ActiveX control, the connection between the application and Crystal Reports can be established by setting the properties of the Crystal object when it is redesigned or changing the properties of the object when it is run again. Through the properties of the Crystal control, you can specify:

The name of the output report in response to an event in the application.

The destination of the report (preview window, disk file or email, etc.). ).

The number of copies you want to print (if the report is submitted to the printer).

Output the information of the file.

Size and location information of the preview window (if the report is displayed in the preview window).

Select formula information (if records in the report are restricted).

Organize information.

Other related attributes.

One thing to note here is that Crystal controls must be used in reports created by Crystal Reports Pro, and reports must be created before attempting to reference reports in VB applications.

3.3 Use of Crystal Report Control

Understand the function of Crystal Reports control, and you can use it. First, select Crystal Report Control in the Component option of Project, and then the Crystal Report Control will be added to the VB toolbox.

Note that the most important property of the Crystal Reports control is ReportFileName, and set it as the file path of the report template customized in Crystal Reports Pro. Then just call the PrintReport method of the control to display the report.

Compared with the data report control, the function of crystal report control is more perfect, and the functions of report preview, printing, editing and modification are all perfect, so in the actual report application design scheme, crystal report is used relatively more. However, the Crystal Reports control also has its limitations, that is, it cannot create custom windows at runtime. You can use the data binding properties of the control to create data-bound reports, but the format of the report itself is handled by the Crystal Reports control. Generally speaking, the Crystal Reports control does not provide field-level access to reports in a program. This defect can be remedied by designing enough reports.

4. Other methods

In addition to the above three methods to achieve report design, of course, you can also use Win32 API to design directly, which is the most flexible and cumbersome way. Because all functions such as editing, modifying and printing are controlled by programs, this method is generally not used, so I will not introduce it here.

5. Summary

Report design is a common problem for programmers. This paper mainly introduces the current mainstream report design scheme. Because there are many knowledge points involved, here is only a brief introduction, hoping to play a role in attracting jade.

/Info_9007.htm