sas

Topic: Creation of ActiveX Documents


     So far we have been looking at the VB projects in its own environment.   With the growth of the internet it has become necessary to make every project Browser enabled.   It is possible to make every  VB Standard EXE project  Browser enabled by converting to what is named as ActiveX Document Project.

Creating the ActiveX Document Project:

     Open the VB IDE and select New from the File menu.   The Project window Dialog appears as shown in the figure 1.  

     Now select ActiveX Document DLL icon.   Immediately the user document form is opened.   Select the ‘project’ item and change its name as ‘demodocproj’ by opening its properties window.   In a similar way select the ‘form’ item and change its name as ‘demodocform’.   Now you can create any project in the form as we do for the Standard EXE project.   In this example we create a project to convert a temperature from Fahrenheit to Centigrade and vice versa.   Drag two labels , one text box and two command buttons, size them, caption them and position them as shown in the figure 2.

     Open the code window and enter the codes as shown in the figure 2a.   Save the form and the project separately the form is saved as demodocform.dob and the project is saved as demodocproject.vbp.

Private Sub Command1_Click()
Text1.Text = ctof(CDbl(Text1.Text))
End Sub



Private Sub Command2_Click()
Text1.Text = ftoc(CDbl(Text1.Text))
End Sub

Function ftoc(temp As Double) As Double
ftoc = (temp - 32) * 5 / 9
End Function

Function ctof(temp As Double) As Double
ctof = temp * (9 / 5) + 32
End Function

        Figure 2a

   Then select ‘Make demodocproj.DLL’ from the File menu.   This will create a document file named demodocform.vbd.   Open the Internet Explorer and view the file ‘demodocform.vbd’.   The project appears as shown in the figure 3 and you can interact with it as you do with any Standard EXE project.

a

                     Figure 1

d01

                         Figure 2

d02
                                Figure 3

Creating the ActiveX Document from an existing Standard  ActiveX EXE Project:

     Suppose you create a Standard EXE project to draw a color gradient.   The design window of the color gradient project looks as in the figure 4.  It contains one Picture box control and three command button controls as shown in the figure 4.   Open the code window and enter the codes as shown in the figure 4a.   Save and run the project and see that the color gradient works properly.   You can experiment with different starting and ending colors for the gradient by changing the values of the variables color1 and color2.    

Private Sub Command1_Click()
Dim newcolor As Long
Dim ipixel, pwidth As Integer
Dim redinc, greeninc, blueinc As Single
Dim color1 As Long, color2 As Long
color1 = RGB(255, 255, 0)
color2 = RGB(0, 0, 0)
startred = getred(color1)
endred = getred(color2)
startgreen = getgreen(color1)
endgreen = getgreen(color2)
startblue = getblue(color1)
endblue = getblue(color2)
pwidth = Picture1.ScaleWidth
redinc = (endred - startred) / pwidth
greeninc = (endgreen - startgreen) / pwidth
blueinc = (endblue - startblue) / pwidth
For ipixel = 0 To pwidth - 1
newcolor = RGB(startred + redinc * ipixel, startgreen + greeninc * ipixel, startblue + blueinc * ipixel)
Picture1.Line (ipixel, 0)-(ipixel, Picture1.Height - 1), newcolor
Next
End Sub

Function getred(colorval As Long) As Integer
getred = colorval Mod 256
End Function
Function getgreen(colorval As Long) As Integer
tgreen = ((colorval And &HFF00FF) / 256&)
End Function
Function getblue(colorval As Long) As Integer
getblue = (colorval And &HFF0000) / (256& * 256&)
End Function

Figure 4a

d03

               Figure 4

     After creating the above Standard EXE project, we will use the Wizard to convert this to document file.   Select ‘ActiveX Document Migration Wizard’ from the ‘Add-Ins’ menu.    Check whether this menu item is available in the ADD-Ins menu.  If not you have get it from ADD-In Manager. You will get the opening screen as shown in the figure 5.   It is only an informative screen.   Then click ‘next’.   You will get the second screen called the Form Selection screen as shown in the figure 6.    Select the form and click ‘next’.   You will get the options screen as shown in the figure 7.  Click the two options, ‘comment out invalid code’ and convert to ActiveX EXE’.   Then click next.    You will get the finish screen as shown in the figure 8.   When you click finish you will get the message box that the document is created.   Now select ‘make gradproj.exe. from the file menu.   This will create the document file  docform1.vbd. You will notice that the document project does not accept the End command given in the exit button.   You can remove that before you start the wizard.     Open the Internet Explorer window and view the docform1.vbd file.   You will find the gradient project working in this screen as shown in the figure 9.

d04

                                      Figure 5

d05

                          Figure 6

d011

                                 Figure 7

d06

                                                     Figure 8

d07

                       Figure 9 
    
Establishing Hyperlinks between two VB documents:

      Create two VB documents  rrdform1.vbd and rrdform2.vbd as shown in the figures 10 and 11 respy.   Each document contains a text box and a command button.   They are captioned as shown in the figures. The code for each of the buttons must be entered in their respective code windows as shown in the figures 10a and 11a.   Save the files.   Open the first file rrdform1.vbd  in the Internet Explorer.   When you click the button, the second file is opened.   When you click the button in the second file the first file is opened.   Hyperlinking documents enables one to navigate through different documents very quickly.

Private Sub Command1_Click()
UserDocument.Hyperlink.NavigateTo "c:\vbproj\rrdform2.vbd"
End Sub

         Figure 10a

Private Sub Command1_Click()
UserDocument.Hyperlink.NavigateTo "c:\vbproj\rrdform1.vbd"
End Sub

       Figure 11a

d08

                               Figure 10

d09

                     Figure 11


Prev

 

 

 

 

 

 

 

 

 


footer back link


 

Error in my_thread_global_end(): 1 threads didn't exit