Table of contents

类型不匹配(错误 13)Type mismatch (Error 13)

office 365 dev account|上次更新日期: 2018/3/13
2 参与人员

Visual Basic 是可以转换并强制指定多个值来完成不可能在早期版本的数据类型分配。不过,此错误还是会出现,并且具有以下原因和解决方案:Visual Basic is able to convert and coerce many values to accomplish data type assignments that weren't possible in earlier versions. However, this error can still occur and has the following causes and solutions:

  • 的原因:变量属性不是类型的正确。例如,要求一个整数值的变量不能接受一个字符串值,除非整个字符串可以被识别为一个整数。Cause: Thevariable orproperty isn't of the correct type. For example, a variable that requires an integer value can't accept a string value unless the whole string can be recognized as an integer.

    解决方案:尝试进行兼容的数据类型之间的分配。例如,一个整数可以始终将分配给一个总是可分配给一个双引号,和任何类型 (除了一种用户定义的类型) 可以分配给一个变量Solution: Try to make assignments only between compatibledata types. For example, an Integer can always be assigned to a Long, a Single can always be assigned to a Double, and any type (except auser-defined type) can be assigned to a Variant.

  • 的原因:对象被传递给单个属性或值需要一个过程Cause: An object was passed to aprocedure that is expecting a single property or value.

    解决方案:通过适当的单个属性或调用方法适合于的对象。Solution: Pass the appropriate single property or call amethod appropriate to the object.

  • 的原因:需要表达式的地方,例如使用模块项目的名称:Cause: Amodule orproject name was used where anexpression was expected, for example:

Debug.Print MyModule 
 **Solution:** Specify an expression that can be displayed.
  • 的原因:您试图混用传统的基本错误处理variant 类型的值的值无错误子类型 (10, vbError ),例如:Cause: You attempted to mix traditional Basic error handling with Variant values having the Error subtype (10, vbError ), for example:
Error CVErr(n) 
 **Solution:** To regenerate an error, you must map it to an intrinsic Visual Basic or a user-defined error, and then generate that error.
  • 的原因:CVErr值无法转换为日期。例如:Cause: A CVErr value can't be converted to Date. For example:
MyVar = CDate(CVErr(9)) 
 **Solution:** Use a **Select Case** statement or some similar construct to map the return of **CVErr** to such a value.
  • 的原因:运行时,此错误通常表示一个variant 类型的值的表达式中使用了不正确的子类型,或在Print #语句中出现的一个variant 类型的值包含一个数组Cause: Atrun time, this error typically indicates that a Variant used in an expression has an incorrect subtype, or a Variant containing anarray appears in a Print # statement.

    解决方案:若要打印数组,创建一个循环来单独显示每个元素。Solution: To print arrays, create a loop that displays each element individually.

有关其他信息,请选择相关项并按 F1(在 Windows 中)或 HELP(在 Macintosh 上)。For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh).

© 2018 Microsoft