VB6中的VarType返回的vbError是什么? [英] What is the vbError returned by VarType in VB6?

查看:330
本文介绍了VB6中的VarType返回的vbError是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在网络上搜索这个,但是一切都在谈论 ErrObject 类,或常量 vbError VarType 函数返回。我想知道这种类型实际上是什么 ,例如一个整数类似于 4 ,一个字符串是一些东西像hello world等。



对于一点点背景,这里是指向官方MSDN页面的链接,关于 VarType ,它显示了它返回的所有常量以及它们所代表的内容。什么是错误值

解决方案

如果您熟悉COM C / C ++,你应该知道,从这个角度来说, VarType()是一个简单的函数,它基本上提取了 vt Variant 的成员作为参数传入。许多地方都记录了 vt 成员的可能值,例如这里



如果您检查COM系统头部(例如WTypes.h)作为Windows SDK),您将看到 VbError 值为10的值确实映射到C / C ++枚举值 VT_ERROR

 枚举VARENUM 
{VT_EMPTY = 0,
...
VT_ERROR = 10 ,
...
};

上面的MSDN链接描述了一个 vt 等于 VT_ERROR ,如下所示:


指定了一个SCODE。错误类型在 scode 中指定。
通常,对错误值的操作应该引发异常,或者将错误传播到返回值。


所以,这基本上是什么意思:



A Variant 显然支持存储许多类型的值,其中包括隐藏存储错误代码的可能性。更正确的是,这些代码正式称为 scode ,因为它们可以指示许多类型的成功以及失败。大多数人将这些代码称为 HRESULT s。



这些代码与VB6中的 Err.Number 中的错误代码类似。所以,你可以告诉一个变式来区分一个错误代码和一个普通的数字。



,几个程序或COM组件(如果有的话)会将错误代码放在Variants中。几乎每个人只是发出COM异常来传达错误(这种机制通过 Err 对象在VB6中暴露出来)。即使那些在COM异常机制之外返回错误代码的组件也可能在类型化变量(例如 Long )中执行。



因此,存在这种可能的返回值的原因是为了完整。你几乎永远都不会在现实生活中看到它。



(编辑:删除位无法创建错误变体@Joe证明我错了您可以使用 CVErr()创建一个)


I have been searching for this all over the web, but everything is either talking about the ErrObject class, or the constant vbError returned by the VarType function. I want to know what that type actually is, e.g. an integer is something like 4, a string is something like "hello world", etc.

For a little background, here is a link to the official MSDN page about VarType, which shows all the constants it returns and what they represent. What is Error value?

解决方案

If you are familiar with COM in C/C++, you should know that from that perspective VarType() is a simple function that essentially extracts the value of the vt member from the Variant passed in as a parameter. The possible values of the vt member are documented in many places, such as here.

If you check inside of the COM system headers (e.g. WTypes.h distributed as part of in the Windows SDK), you will see that the VbError value of 10 indeed maps to the C/C++ enum value of VT_ERROR.

enum VARENUM
    {  VT_EMPTY   = 0,
       ...
       VT_ERROR  = 10,
       ...
    } ;

The MSDN link above describes the meaning of a vt that equals VT_ERROR as follows:

An SCODE was specified. The type of the error is specified in scode. Generally, operations on error values should raise an exception or propagate the error to the return value, as appropriate.

So, here's basically what it means:

A Variant obviously supports storing many types of values, and among them is the obscure possibility of storing an "Error Code". More correctly, these codes are formally called scode's, because they can indicate many types of "success" as well as "failures". Most people refer to these codes as HRESULTs.

These codes are the same kind of "Error Codes" that you get from Err.Number in VB6. So, you can tell a Variant to distinguish an "Error Code" from just a plain number.

In reality, few programs or COM components - if any - will ever put error codes in Variants. Almost everybody just issues COM Exceptions to communicate errors (this mechanism is exposed in VB6 via the Err object). Even those components that return error codes outside of the COM Exception mechanism, would likely do so in typed variables (e.g. Long's).

Therefore, the reason this possible return value exists is for completeness. You will almost never see it in real life.

(Edit: Remove bit about not being able to create an "Error" variant. @Joe proved me wrong on that. You can use CVErr() to create one)

这篇关于VB6中的VarType返回的vbError是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆