Interaction between VBScript and ActiveX Control

This is a piece of code which shows the interaction between VBScript and ActiveX Control.

If you have a method in ActiveX Control which takes a Variant array to initiate the control for some
purpose. Use this easy tip.

Step 1 :

In the ActiveX control say we have a function called AssignControlValues which takes the array of Variant
Declare the function like the following

Public Function AssignControlValues _
      (controlvalues As Variant)
dim controlarray as variant
dim maxvalues as integer
maxvalues  = UBound(controlvalues)
redim controlarray(maxvalues)
for i=0 to maxvalues
next i
End function

Step 2 :

At the VBScript side

Declare the object
<object classid="CLSID:XXXX" _

We can call the method in the ActiveX control from the VBScript using the Object ID just declared above

<script language="vbscript">
dim controlvalues
controlvalues(0)=text1.text    ' Assign values to the control array
controlvalues(1)=combo1.text   ' Either u get it from the HTML
                               ' Controls or anything else

call Object1.AssignControlValues controlvalues    ' pass the array
                                                  ' as variant
                                                  ' object


This way the user can pass the entire array with a single method call instead of passing with the ActiveX
This is very usefull for the interaction between VBScript and ActiveX Control.
Note : The method of object could be called with the values of elements in the ActiveX control also.

More by Author

Must Read