Using VB to access the Internet

Source: Internet
Author: User
Tags html page connect ole

Currently, there are a number of construction modules that can help users create an ActiveX control collection called a Hyper-client (rich client) Internet application that includes visual Basic (hereinafter referred to as VB). They can provide features such as SMTP and POP mail services, FTP, newsgroup, and Web Access. In addition, the use of OLE can also make Web Access automated. This article introduces the two methods.

Embed an ActiveX control in an application

Using the Crescent Internet ToolPak (Internet Toolkit) control that conforms to the HTTP protocol, you can connect VB applications to a Web site, transfer data to a site, and get an HTML page from a site. The Crescent HTTP control does not actually display the downloaded HTML page, but enables the application to use the page data as a string. For example, if the server produces an HTML file called myresult.html to reply to a request from a client, the client application can obtain and download the file through a crescent Active x connection to the server. The code snippet for establishing the connection is as follows:

CIHTTP1. Hostname= "Www.cnblogs.com"

CIHTTP1. Url= "Resul ts\myresult.html"

Chttp. Parseincomingdata = True

CIHTTP1. Conn Ecttoserver

Once the ActiveX control establishes a connection to the server, it triggers the Httpserverconnection event. At this point, the application issues a command Cihttp1.get, retrieves the page specified in the RL property, and the control activates the Fileclosed event to retrieve the specified page. The application reads the page text through the Actvex properties Htmlpagetext withtags (Htmlpagetextwithouttgs with attributes when the home page does not have HTML code embedded). The code is as follows:

Mytext= CIHTTP1. Htmlpagetextwithtags

If you do not want to use the control to download the entire home page, you can quickly scan the page data by using the packet parameter of the control's Packetreceived event. The packetreceived event is activated whenever the control accepts data from the server.

In addition, the client application can use HTTP controls to extract Web page data from a standard browser. For example, Actvex controls connect to the web behind the scenes and download pages that are being published, allowing traditional client applications to continuously receive the latest WB information and change existing content.

To further simplify processing, you need to set the properties before the ActiveX control is connected to the Web page. The Crescent HTT control can also add the URL address of the download page, the address of the image file, and all HTML command files to the specified three list boxes.

Automating Web Access with OLE

In addition to ActiveX controls, there is a way to automate the interaction between an application and the Web, which is OL automation, which uses OLE Automation to build a traditional application, and then pass it. The OLE Automation server interface for the browser makes automatic Web connections. Both Netscape Navigator and Microsoft Internet Explorer version 3.0 support OLE Automation.

The OLE Automation interface for Netscape Navigator is designed specifically for this purpose. For example, the OL Automation interface lets navigator open a Web page that does not display the page in its own browser window, but instead downloads the content of the page, replicates it to the server object's data buffer, and allows the client's application to access the content.

For example, suppose you want navigator to open a Web page in Excel, you must first use the Excel Reference dialog box to refer to the Netscape.tlb library in the Navigator program directory, and then take the Navigator object as an instance, and complete the function of opening the page. The code is as follows:

Dim Nav as Object, result as Boolean

Dim URL as String

Const Urlget =0

Const urlpost=1

Url=http://www.cnblogs.com/index.html

Set Nav=creatobject ("Netscape.netork")

Result=nav.open (Url,urlget, ",", 0, "")

If the Automation object's property isfinished is set to True, the contents of the page can be carefully processed through the object buffer.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.