Visual Basic Script (VBScript)
Listed below are the questions that we are asked quite often. Before you write us, be sure to check here.

Programming

Programming

Adding a component to a web page, using the OBJECT tag

The syntax for adding a component to a web page is:
<OBJECT classid="clsid:CLASSIDENTIFIER" id="IDENTIFIER">
</OBJECT>

where 

  • the IDENTIFIER is the ID of the object being added. The ID attribute can be used by a VB Script (via the HTML DOM) or by CSS to make changes or style the element with the specified id. The id attribute specifies a unique id for an HTML element
  • the CLASSIDENTIFIER is the object's class identifier as CD481F4D-2D25-4759-803F-752C568F53B7

The CLASSIDENTIFIER is unique for each /COM object, and can be found on control's documentation on the main object page, where something like follows is displaying, or explained here;

Tip The /COM object can be placed on a HTML page (with usage of the HTML object tag:  <object classid="clsid:...">)  using the class identifier: {CD481F4D-2D25-4759-803F-752C568F53B7}. The object's program identifier is: "Exontrol.G2antt". The /COM object module is: "ExG2antt.dll"

The following sample adds the eXG2antt component to a web page:

<OBJECT classid="clsid:CD481F4D-2D25-4759-803F-752C568F53B7" id="G2antt1">
</OBJECT>

 

Where I should initialize my control?

A) You can call the Init method during load event of the Body HTM element, like in the following sample:
<BODY onload='Init()'>
<OBJECT classid="clsid:CD481F4D-2D25-4759-803F-752C568F53B7" id="G2antt1" width="192" height="192">
</OBJECT>

<SCRIPT LANGUAGE="VBScript">
Function Init()
	With G2antt1
		.Columns.Add "Task"
		.Chart.FirstVisibleDate = #1/1/2001#
		With .Items
			.AddBar .AddItem("Task 1"),"Task",#1/2/2001#,#1/4/2001#
		End With
	End With
End Function
</SCRIPT>
</BODY>

B) You can add a SCRIPT right after the </OBJECT> so the code is executed once the object is created as in the following sample:

<OBJECT classid="clsid:CD481F4D-2D25-4759-803F-752C568F53B7" id="G2antt1">
</OBJECT>

<SCRIPT LANGUAGE="VBScript">
	With G2antt1
		.Columns.Add "Task"
		.Chart.FirstVisibleDate = #1/1/2001#
		With .Items
			.AddBar .AddItem("Task 1"),"Task",#1/2/2001#,#1/4/2001#
		End With
	End With
</SCRIPT>

Handling Custom Events or Events with Parameters

The syntax for handling the events with parameters is:
<SCRIPT LANGUAGE="VBScript">
Function IDENTIFER_EVENT(PARAMETERS)
	
End Function
</SCRIPT>

where the IDENTIFIER is the ID of the object being handled, and the EVENT is the name of the event being handled. The PARAMETERS gets the list of parameters that the event carries.

The following VBScript example displays a message box when the user clicks an anchor element in the gantt control:

<SCRIPT LANGUAGE="VBScript">
Function G2antt1_AnchorClick(AnchorID,Options)
	alert(AnchorID)
End Function
</SCRIPT>

The sample handles the AnchorClick event of the eXG2antt component.

Event not fire during initialization

Initializes the control using the option A), as described on: Where I should initialize my control? ( using the load event of the BODY element ). 

Changing the parameters by reference do not work during events, such as KeyCode parameter of KeyDown(KeyCode,Shift) event

Some of the events pass the parameters by reference. Such of event could be the KeyDown event, where the KeyCode parameter is passed by reference, so user can change it runtime. 

For instance, the following VBScript sample changes the TAB behavior, so if user presses the TAB, the control sends instead the RIGHT key, so it advance to the next editable field:

<SCRIPT LANGUAGE="VBScript">
Function G2antt1_KeyDown(KeyCode,Shift)
	if ( KeyCode = 9 ) then
		KeyCode = 39
	end if
End Function
</SCRIPT>

In this code, the KeyCode = 39, won't have any effect so instead you have to use the EventParam property like shown in the following sample:

<SCRIPT LANGUAGE="VBScript">
Function G2antt1_KeyDown(KeyCode,Shift)
	if ( KeyCode = 9 ) then
		G2antt1.EventParam(0) = 39
	end if
End Function
</SCRIPT>

or an equivalent sample:

<SCRIPT LANGUAGE="VBScript">
Function G2antt1_KeyDown(KeyCode,Shift)
	if ( KeyCode = 9 ) then
		G2antt1.Template = "EventParam(0) = 39"
	end if
End Function
</SCRIPT>

 The EventParam property is available for almost all of our components. The Template property specifies the x-script code to be executed at runtime.

How can I find the CLASSIDENTIFIER I should use to instantiate the control on a web page?

The class identifier can be found on the control's documentation. 

You can follow the steps to find the classid ( for instance, we are trying to get the classid for the exg2antt control ): 

Under the object's help you will find:

Tip The /COM object can be placed on a HTML page (with usage of the HTML object tag:  <object classid="clsid:...">)  using the class identifier: {CD481F4D-2D25-4759-803F-752C568F53B7}. The object's program identifier is: "Exontrol.G2antt". The /COM object module is: "ExG2antt.dll"

Type mismatch: 'ItemFromPoint'

The ItemFromPoint(X as Long, Y as Long, ByRef ColIndex as Long, ByRef HitTestInfo as HitTestInfoEnum) method requires four parameters. Because, any variable on VBScript is of Variant type, the ColIndex and HitTestInfo can not be passed the right way. In order to get the result of the ItemFromPoint you need to use the ExecuteTemplate method like in the following sample:
<SCRIPT LANGUAGE="VBScript">
Function Grid1_MouseMove(Button,Shift,X,Y)
	With Grid1
		h = .ExecuteTemplate("Dim c, hit;ItemFromPoint(-1,-1,c,hit)")
		alert( h )
	End With
End Function
</SCRIPT>

instead of:

<SCRIPT LANGUAGE="VBScript">
Function Grid1_MouseMove(Button,Shift,X,Y)
	With Grid1
		Dim c, hit
		h = .ItemFromPoint(-1,-1,c,hit)	' Generates the Type mismatch: 'ItemFromPoint'
		alert( h )
	End With
End Function
</SCRIPT>

In the same way, if you require to access the c or hit variables you should use a code like:

<SCRIPT LANGUAGE="VBScript">
Function Grid1_MouseMove(Button,Shift,X,Y)
	With Grid1
		h = .ExecuteTemplate("Dim c, hit;ItemFromPoint(-1,-1,c,hit);c=c")
		alert( h )
	End With
End Function
</SCRIPT>
Copyright 1999-2017 Exontrol. All rights reserved.