In VB6, do declared fields have default values?

2019-06-17 05:01发布

问题:

I am going through some old VB6 code and in many forms, I encounter declaration statements like -

 PEC_NUM_ENT(1) As Byte
 EC_MORE_RW_EXIST(0) As Byte
 EC_CODE_IND(0) As Byte
 EC_DATA(7) As PRXDetail 

My question is, do these fields have default values? If so, what are the values? Thanks.

回答1:

Yes. Numerical and date types default to 0, strings to an empty string (i.e., ""), boolean to False, and variant to EMPTY.



回答2:

From the VB6 documentation

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.

PRXDETAIL looks like it might be a user-defined type



标签: vb6