新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Sub Command1_Click()
Dim a As Integer
Dim b, c As Integer
Dim d
Debug.Print a, TypeName(a)
Debug.Print b, TypeName(b)
Debug.Print c, TypeName(c)
d = 1.23
Debug.Print d, TypeName(d) '分配成Double
b = a
Debug.Print "b=" & b, TypeName(b) 'Empty变Integer
b = 1.93
Debug.Print "b=" & b, TypeName(b) 'Empty变Double
a = b
Debug.Print "a=" & a, TypeName(a) 'a还是Integer,但四舍五入值
End Sub
运行结果:
0 Integer
Empty
0 Integer
1.23 Double
b=0 Integer
b=1.93 Double
a=2 Integer
可以看出b是空,所以建议b As Integer。