大网数据广告活动
Windows 系统接口

Syntax Differences

· 52CE 我爱测

The most apparent change as you move between programming languages is the change in syntax.

The most apparent change as you move between programming languages is the change in syntax.

Consider the EnhEvents object's Add method, shown as it is declared in three different languages.

object.Add(Time As Double, Name As String) As Variant

HRESULT Add(
  double Time, 
  BSTR Name, 
  VARIANT* pVal
);
 
public com.ms.com.Variant Add( 
  double Time, 
  java.lang.String Name
);
 

Although the syntax of each language expresses the method differently, the functionality is the same. In each language, the Add method takes the parameters Time and Name and returns an EnhEvent object. In the C++ example, the method returns the object by using a third, output parameter, pVal.

Typically, the functionality of a COM object is the same across programming languages. Because of this, documentation for a COM object is useful even if the object is documented in another programming language than the one you are using. The descriptions of the object's functionality, parameters, and return values are, with few exceptions, valid for all languages.

For information about how to convert the syntax of a COM object to another programming language, see Translating COM Object Syntax for Programming Languages.

The syntax differences among the scripting languages JavaScript, JScript, and VBScript are less pronounced than the syntax differences among the programming languages shown preceding. For example, consider the square function as it is implemented in each of these three scripting languages:

Function square(x)
  square = x*x
End Function
 
function square(x){ return x*x; }
 
function square(x){ return x*x; }
 

Notice that the scripting languages, unlike the programming languages, are weakly typed. In other words, you do not have to specify the data type of a parameter or return value when you declare a function. Instead, the variables are automatically cast to the appropriate data type. In the case of VBScript, all variables are of the same data type, Variant.

The JavaScript and JScript syntax for square is the same. JScript is largely compatible with JavaScript. However, JScript includes some objects not currently supported by JavaScript, such as ActiveXObject, Enumerator, Error, Global, and VBArray. For more information about these objects, see the JScript Language Reference.

On the surface, JavaScript and JScript syntax resembles Java syntax. This similarity is only superficial. The Java language was developed independently from both JavaScript and JScript and is not related to either.

VBScript, on the other hand, is a subset of the Visual Basic programming language. Because of this, VBScript syntax is a subset of Visual Basic syntax and is often interchangeable with Visual Basic syntax.

For information on using COM objects in scripting languages, see Scripting with COM Objects.

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。