Since the popularity of the Internet, it has become much more convenient for people to download files, obtain instant information, and send emails. The Internet can be said to be a major innovation of human technology in the 21st century. Due to this major change, people's lifestyles have also been greatly affected; electronic shopping, online information databases, and real-time online stock market transactions have mushroomed. In the past, Visual Basic 4.0 did not provide a complete solution for Visual Basic enthusiasts to design Internet programs. Fortunately, Visual Basic 5.0 provides some controls for us to design Internet-related programs. In this article, the author will use InternetTransfercontrol with WebBrowsercontrol to tell readers how to easily design Browser and FTP programs with Visual Basic 5.0.
Introduction to Control
InternetTransfercontrol
InternetTransfercontrol is a control provided by Microsoft to facilitate users in designing Internet applications. It provides two InternetPRotocols: HTTP and FTP. When we use it, we must first set its access method. Access methods are divided into two types: directly connecting to the Internet network, or connecting to the Internet network through a proxy, which is completely determined by the nature of our network. After we set the relevant parameters, InternetTransfercontrol provides two methods: OpenURL and Execute to allow us to perform network-related operations. We can use these two commands to execute some Internet commands. In the design below, the author will explain its usage.
WebBrowsercontrol
WebBrowsercontrol was first provided by IE3.0 and will be automatically loaded when IE3.0 is installed; VisualBasic5.0 turns it into an internal control. It provides Navigatemethod that enables us to connect to the WWWServer where we want to go.
Readers must be wondering: Since InternetTransfercontrol can connect to the Internet through HTTP and TPprotocol, what do we need WebBrowsercontrol for? Just because InternetTransfercontrol does not provide a graphics mode access method, the resulting file can only be transferred back in text mode. If the returned file contains graphics, the resulting HTML file must be converted using a program. So the author chose WebBrowsercontrol to help us make a conversion.
Let the author tell readers how to design WebBrowser and FTPclient.
WebBrowser programming
Step1: Set the network parameters
First we need to know whether our network system is directly connected to the Internet or connected to the Internet through a proxy. We can determine how our system is connected to the Internet through the following steps:
Double-click on the "My Computer" option to enter the "Control Panel". Double-click on the "Internet" option in the "Control Panel" option. Select connection in InternetDialogBox. From the DialogBox displayed on the screen, you can know whether the system is connected to the Internet through proxy or dialing. Since the author's system is connected to the Internet through a proxy, we must find out the address and port of the proxyServer to facilitate program setup.
Then click the "setting" option to view its address and port. The screen will then display a DialogBox with "addressofproxytouse":172.18.16.65 and "port":8080 recorded in it. Record this, you will need these parameters later.
Step2: Start the design process
Select NewProject in the File option to create a new project. You will see many options on the screen, such as ActiveXDocument.EXE, ActiveXDocument.DLL, ActiveX.EXE, ActiveXControl, etc. At this time, you must select Standard.EXE.
Then under Project, select the Property attribute option, and change ProjectName to Webbrowser under the general option. Add a Webbrowsercontrol to the Form on the screen and name it web1; then add an InternetTransfercontrol and name it Inet1.
Add three TextBoxcontrols named CGISearch, webname and htmlshow respectively, add a Label in front of CGISearchTextBox, and change its Caption to Search.
Add three Buttoncontrols named Search, Go and ShowDoc. Change Caption to Se respectively
arch, goto and showdocument.
In order to facilitate readers to understand the relationship, the following is explained in a table:
(TextBox)
Name
--------------------------------------------------
CGISearch (enter CGI command)
webname (enter the webaddress you want to go to)
htmlshow (display html text results)
(Button)
NameCaption
-------------------------------------------------- --------------------------
-----
Search(execute CGI command)search
Go (execute the action to webaddress) Goto
ShowDoc (display html text results)showdocument
Then set the various properties of Inet1 as follows:
accesstype=2-icnamedproxy
protocol=4-icHTTP
proxy=172.18.16.65:8080
Add the following program code to Go_Click(). This action is to connect to the webServer you want to go to and display the screen in the square area of web1:
PrivateSubGo_Click()
web1.Navigatewebname.Text
EndSub
The above program uses the Navigate of web1. This method connects the screen to the website specified in the webnameTextBox.
Add the following program code to htmlshow_Click():
PrivateSubhtmlshow_Click()
a$=web1.LocationURL
ShowDoc.Text=Inet1.OpenURL(a$)
EndSub
The above program first reads the URLaddress that web1 is connected to through the LocationURL property, and temporarily stores it in the string a. Then use the OpenURL() command to display the received HTML program code in the ShowDoc TextBox.
Add the following program code to CGIserch_Click():
PrivateSubCGIserch_Click()
Web1.Navigate"http://search.yahoo.com/bin/Search?p=" CGI.
Text
EndSub
This action uses CGI commands to query the file. Here we specify the query command to be sent to Yahoo, the web search site.
In this way we have completed a small WebBrowser.
Step3: Test program
Execute the WebBrowser you just designed, and fill in the URL you want to go to in the TextBox of webname. Here we set it to http://www.Microsoft.com. Then press the GoButton, and you will see Microsoft's HomePage displayed in the square area of web1control.
Press ShowDocButton, you will be able to see the HTML program code of MicrosoftHomePage in the htmlshow TextBox.
Next let's try the CGI search function. After adding communication to CGIserchTextBox, we found that the query results were displayed in the web1 square area.
Similarly, we can also press the ShowDocButton to see the HTML program code returned by the query results in the htmlshow TextBox.
Congratulations on your success!
FTP programming
As mentioned earlier, InternetTransfercontrol can provide FTPprotocol. Here we will tell you how to use InternetTransfercontrol to design a client program that can connect to FTPServer and download the bbb.txt file on FTPServer to the local end.
Step1: Programming
Select NewProject in the File option to create a new project. You will see many options on the screen, such as ActiveXDocument.EXE, ActiveXDocument.DLL, ActiveX.EXE, ActiveXControl, etc. At this time, select Standard.EXE. Then under Project, select the Property attribute option, and change ProjectName to FTPclient under the general option.
Add an InternetTransfercontrol to the Form on the screen and name it Inet1. Set the parameters of Inet1property as follows:
Accesstype=2-icnamedproxy
Username="david"
passWord="2333334"
protocol=2-icFTP
proxy=172.18.16.65:8080
We set the Username and password here. When we log in to the FTP Server, the Server will directly skip the screen for entering the Username and password.
Add a TextBoxcontrol and name it FTPgetfile. Add two Buttoncontrols, name them FTPget and FTPLink, and change their Captions to FTPget and FTPLink respectively.
Add the following program code to FTPLink_Click():
PrivateSubFTPLink_Click()
Inet1.excute"FTP128.9.200.4"
EndSub
Execute is a method provided by InternetTransfercontrol for executing FTP utilities. We can add FTP commands after it, so that we can use any familiar FTP utility to complete the work. The author's FTPServer address is 128.9.200.4, so we fill in this address after the FTP command.
Then add the following program code to FTPget_Click():
PrivateSubFTPLink_Click()
Inet1.excute"GETaaa.txtc:/bbb.txt"
EndSub
This action is to transfer the aaa.txt file on the FTPServer to the client.
Step2: Test
Execute FTPclient, press FTPLinkButton, and connect to FTPServer. Press the FTPgetButton to retrieve the file. Have you noticed that there is an extra file bbb.txt under the C:/ directory? Congratulations on your success! ->