Access the Internet using VB

Source: Internet
Author: User

Access the Internet using VB

Currently, many construction modules can help you create an Internet application named rich client, including a set of ActiveX controls for Visual Basic (VB. They can provide SMTP and POP mail services, FTP, newsgroup, and Web access. In addition, Ole can be used to automate web access. This article introduces the two methods.

Embed the Active X control in the Application

Using the http-Compliant Control of the Crescent Internet toolpak (Internet Toolkit), you can connect a VB Application to a Web site, transfer data to the site, and obtain HTML pages from the site. The crescent HTTP control does not display the downloaded HTML page, but enables the application to use page data in the form of strings. For example, if the server returns an HTML file named myresult.html to a request from the client, the client application can obtain and download the file through the Crescent Active X connection established with the server. The code snippet for establishing a connection is as follows:

Cihttp1.hostname = "myresult.myhost.com" cihttp1.url = "results/myresult.html" Ci HTTP. parseincomingdata = truecihttp1.connecttoserver once the Active X control establishes a connection with the server, it triggers the httpserverconnection event. In this case, the application sends the command cihttp1.get to retrieve the page specified in the u rl attribute, and then the control activates the fileclosed event to retrieve the specified page. The application reads the page text through the htmlpagetext withtags attribute of acti ve X (when the home page does not contain HTML code, the HTML pagetextwithoutta GS attribute is used. 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 page data through the packet parameter of the control packetreceived event. The packetreceived event is activated every time the control receives data from the server.

In addition, client applications can also use HTTP controls to extract web page data from standard browsers. For example, the acti Vex control establishes a connection with the Web behind the scenes and downloads the released page, allowing traditional Client Applications to continuously receive the latest we B information and change the original content.

To further simplify processing, you must set properties before connecting ActiveX controls to web pages. The HTTP control of the Crescent can also add the URL address of the download page, the address of the image file, and all the HTML command files to the specified three lists respectively.

Use OLE to automate Web Access

In addition to ActiveX controls, there is also a way to automate the interaction between applications and the web, which is OLE Automation, that is, using OLE automation to establish traditional applications, then, use the OLE Automation server interface of the browser to perform automatic web connection. Both Netscape Navigator and Microsoft Internet Explorer 3.0 and later support OLE automation.

The OLE Automation interface of Netscape Navigator is designed for this purpose. For example, the OLE Automation interface enables navigator to open a Web page. Instead of displaying this page in its own browser window, it downloads the content of this page and copies it to the data buffer of the server object, allow client applications to access the content.

For example, if you want navigator to open a web page in Excel, you must first use the Excel "Reference" dialog box to reference Netscape in the navigator program directory. TLB library, and then use the navigator object as an instance, and complete the page opening function. The Code is as follows:

Dim nav as object, result as booleandim URL $ const urlget = 0 const urlpost = 1ur L $ = http://www.microsoft.com/indev/default.htmset nav = creatobject ("Netscape. netw ork ") Result = nav. open (URL $, urlget, ",", 0, "") if the isfinished attribute of the automation object is set to true, You can carefully process the content on the page 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.