PRB: Changes to ByRef Parameters in Script Event Handlers Are Not Passed to Controls (253282)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Internet Explorer (Programming) 4.01 SP1
  • Microsoft Internet Explorer (Programming) 4.01 SP2
  • Microsoft Internet Explorer (Programming) 5
  • Microsoft Internet Explorer (Programming) 5.01
  • Microsoft Internet Explorer (Programming) 5.5
  • Microsoft Visual Basic, Scripting Edition 3.0
  • Microsoft Visual Basic, Scripting Edition 4.0
  • Microsoft Visual Basic, Scripting Edition 5.0
  • Microsoft JScript 3.0
  • Microsoft JScript 4.0
  • Microsoft JScript 5.0
  • Microsoft Visual Basic Professional Edition for Windows 4.0
  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 4.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

This article was previously published under Q253282

SYMPTOMS

When a Visual Basic ActiveX control fires an event that is handled in script, changes that are made to the event's ByRef parameters are not passed back to the control.

CAUSE

The default OLE Automation Marshaller cannot convert a strongly-typed ByRef parameter into a ByRef Variant, so it converts the parameter into a normal ByVal Variant, and passes that to the scripting engine.

RESOLUTION

To allow Visual Basic Script (VBScript) event handlers to change parameter values of events that are fired by Visual Basic ActiveX controls, declare the parameters as ByRef Variants. JScript event handlers are only able to change the values of these ByRef Variants if they contain Object references, because JScript passes all variables by value (not by reference), in accordance with the ECMA-262 specification.

MORE INFORMATION

Many of the controls that are included with Visual Basic have events that use strongly-typed (nonvariant) ByRef parameters. For example, the Microsoft DataGrid Control has a ByRef Cancel parameter for its BeforeColUpdate event.

Due to their popularity in Visual Basic, these controls are also widely used in Web pages. Most of these controls, however, were not designed for this environment, and you should consider this limitation before you use any of these controls in a scripting context.

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

269258 INFO: JScript Passes Variables by Value


Modification Type:MajorLast Reviewed:6/28/2004
Keywords:kbnofix kbprb KB253282