VBA变量/数组的默认值 [英] VBA variable/array default values

查看:1097
本文介绍了VBA变量/数组的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑的声明

Dim x As Double
Dim avg(1 To 10) As Double

什么是X在默认值平均

通过测试,我想说的是, X 初始化为零。
同样,我想说的是,在平均的所有元素都初始化为零。

Through testing, I want to say that x is initialized to zero. Likewise, I want to say that all elements in avg were initialized to zero.

不过,我可以写code依赖呢?或者是默认的初始值居然不确定?

However, can I write code that depends on this? Or are the default initialization values actually indeterminate?

推荐答案

如果您指定数据类型,但是没有指定初始化时,Visual Basic变量初始化为它的数据类型的默认值,这对于所有数值类型为0(零)。

If you specify a data type but do not specify an initializer, Visual Basic initializes the variable to the default value for its data type, which for all numeric types is 0 (zero).

当您运行宏,所有的变量都被初始化为一个值。一个
  数值变量被初始化为零,可变长度字符串是
  初始化为零长度字符串(),和一个固定长度的字符串是
  充满ASCII code 0 Variant变量被初始化为
  空。一个空的变量是一个零在数字环境psented重新$ P $
  和零长度字符串()在字符串上下文中。

When you run a macro, all the variables are initialized to a value. A numeric variable is initialized to zero, a variable length string is initialized to a zero-length string (""), and a fixed length string is filled with the ASCII code 0. Variant variables are initialized to Empty. An Empty variable is represented by a zero in a numeric context and a zero-length string ("") in a string context.

参考

这篇关于VBA变量/数组的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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