VB6 中未设置的变体的默认值是什么? [英] What is the default value for an unset variant in VB6?
问题描述
我正在处理一些旧代码,它定义了一个像这样的全局变量...
I am working with some old code and it defines a global variable like this...
Public myvar
这个变量永远不会被赋值,但后来在测试中使用......
This variable is never assigned a value, but is later used in a test...
If myvar <> somevalue then
'do something
End If
对于 somevalue 的什么值会做某事?
For what values of somevalue would that something be done?
推荐答案
- 默认值为
Empty
. - 对于除
Empty
、0
或""
之外的任何值都将完成某事"...- ... 对于 Nothing 值,代码将引发错误并且某些事情将无法完成".
- The default value is
Empty
. - "Something will be done" for any value except
Empty
,0
or""
...- ... for the value Nothing, the code will raise an error and "something will not be done".
来自 VB6 文档
当变量被初始化时,一个数值变量初始化为 0,可变长度字符串是初始化为长度为零的字符串(""),一个固定长度的字符串是用零填充.变体变量被初始化为空.每个元素一个用户定义的类型变量是初始化就好像它是一个单独的变量.
When variables are initialized, a numeric variable is initialized to 0, a variable-length string is initialized to a zero-length string (""), and a fixed-length string is filled with zeros. Variant variables are initialized to Empty. Each element of a user-defined type variable is initialized as if it were a separate variable.
这篇关于VB6 中未设置的变体的默认值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!