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
values
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
controlarray(i)=controlvalues(i)
next i
End function

Step 2 :

At the VBScript side



Declare the object
<object classid="CLSID:XXXX" _
       CODEBASE="http://vbsource/object.CAB#Version=2,0,0,0
id="Object1>

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
controlvalues(2)=text3.text
controlvalues(3)=list1.name
controlvalues(4)=text1.text

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

</script>

This way the user can pass the entire array with a single method call instead of passing with the ActiveX
property.
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

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read