Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Load documents into Internet Explorer

This source code snippet requires TX Text Control ActiveX
Author:TX Text Control Support Department
Language:Visual Basic
Version:1.1
Released:April 04, 2001
Last modified:January 11, 2008
Requirements:TX Text Control ActiveX with Visual Basic 6.0
Download code:network.zip Download [960 B, ZIP]

Using TX Text Control in Microsoft Internet Explorer only makes sense if you can actually load documents that lie on other computers - for example on a file server. Microsoft provides a control that makes this task very easy.

It's called MSInet.ocx and is available for download from http://www.microsoft.com if it's not already installed on your machine.

The following sample is written in plain HTML using VBScript.

Here is how it works:

  1. <OBJECT
  2. ID="Inet1"
  3. CLASSID="CLSID:48E59293-9880-11CF-9754-00AA00C00908" >
  4. </OBJECT>
  5.  
  6. <OBJECT
  7. id=objTX
  8. classid="clsid:3D6D5D2F-B9F2-101C-AED5-00608CF525A5"
  9. width="100%"
  10. height="90%" >
  11. <PARAM NAME="ViewMode" VALUE="2">
  12. <PARAM NAME="ScrollBars" VALUE="3">
  13. <PARAM NAME="PageWidth" VALUE="12000">
  14. <PARAM NAME="PageHeight" VALUE="16000">
  15. <PARAM NAME="Text" VALUE="TX Text Control ActiveX in Internet Explorer">
  16. </OBJECT>

In addition to the TX Text Control control, an Inet control is placed in the HTML code. It will not be visible later on, but we can use it to perform a variety of tasks. This example will only show how to download documents using HTTP, but FTP is possible as well.

Three buttons are also placed in the HTML file. Here are their event handlers:

  1. Sub GetTXT_onClick()
  2. Dim strData
  3. strData = Inet1.OpenURL("http://www.example.com/path/to/msie_demo.txt", icString)
  4. objTX.LoadFromMemory strData, 1, False
  5. End Sub
  6.  
  7. Sub GetHTM_onClick()
  8. Dim strData
  9. strData = Inet1.OpenURL("http://www.example.com/path/to/msie_demo.htm", icString)
  10. objTX.LoadFromMemory strData, 4, False
  11. End Sub
  12.  
  13. Sub GetRTF_onClick()
  14. Response = Inet1.Execute("http://www.example.com/path/to/msie_demo.rtf", "GET")
  15. If Inet1.ResponseCode <> 0 Then
  16. MsgBox ("ErrorCode: " & Inet1.ResponseCode)
  17. MsgBox ("Error: " & Inet1.ResponseInfo)
  18. End If
  19. End Sub

In the first two handlers the Inet control's OpenURL method is used to download a file into a variable. This variable is then loaded into the TX Text Control using TX's LoadFromMemory method.

The third handler shows another way of loading a file. It uses the Inet Control's Execute method. The difference between the two methods is that the OpenURL method does not return until the file is downloaded. So, the application seems to hang.

The execute method lets the Inet control send a message when data arrives. Here is the handler for this message:

  1. Sub Inet1_StateChanged(State)
  2.  
  3. Select Case State
  4. ' ... Other cases not shown.
  5.  
  6. Case 12 ' icResponseCompleted
  7. Dim strData: StrData = ""
  8. Dim vtData
  9.  
  10. ' Get first chunk.
  11. vtData = Inet1.GetChunk(10240, icString)
  12.  
  13. Do While Len(vtData) <> 0
  14. strData = strData & vtData
  15. ' Get next chunk.
  16. vtData = Inet1.GetChunk(10240, icString)
  17. Loop
  18. objTX.LoadFromMemory strData, 5, False
  19. End Select
  20. End Sub

The Inet control has 12 states. In this example only state no. 12 is of interest. When the control has reached this state, all data is downloaded. Using the GetChunk method, the data is stored in a variable and then loaded into TX Text Control with the LoadFromMemory method.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place