vb输出结果判断

private x as integerprivate sub command1_click() static y as integer dim z as integer n=10 z=n+z y=y+z x=x+z label1.caption=x label2.caption=y label3.caption=zend sub为什么结果是30 30 10而不是10 30 10不是只有y能累加吗
2026年09月20日 21:17
有2个网友回答
网友(1):

private x as integer 全局变量 也可累加
虽然你写 private 私有化 在其他窗体无法引用,但在这个窗体里 是全局

网友(2):

n是哪里定义的?


x是全局的,在整个程序执行中都不会被归零。

 

private sub command1_click()
    static y as integer
    Private x as integer
    Dim z as  integer
    n=10
    z=n+z
    y=y+z
    x=x+z
    label1.caption=x
    label2.caption=y
    label3.caption=z
End Sub

  这样就是10 30 10