子程序开始时,VBA Globalvariables复位为0

我正在写一个使用全局variables的项目。 全局variables是在模块的开始处声明的,所有的代码都在同一个模块中。 全局variables(应该)在每个子程序之间传递,由于工作表的性质,它们的值是在不同的子程序或函数中声明的,具体取决于需要什么。

我的问题是,每次我调用一个子程序,我的全局variables被重置为0,这明显挫败了一个全局variables的目的。

有什么明显的可能导致这个? 我的代码相当大(1200+行),这是不实际的张贴在这里。

电子表格具有被删除和重绘的形状。 这可以重新编译表,并导致所有的全局variables重置?

谢谢

编辑:variables声明

Public Type Blockwall Asd As Single 'max area of reinforcement allowed Ast As Single 'Area of reinforcement in design tension zone Bar As Integer 'bar size Capacity As Single 'Calculated capacity of wall usign Ast cover As Single 'cover to reinforcement d As Single 'Depth to centre of tension steel Depth As Single 'Thickness of wall/footing DesignMoment As Single 'Design Moment in base of wall DL As Load 'Dead Load force LL As Load 'Live Load Force fc As Single 'Compressive strength of concrete/grout fm As Single 'compressive strength of masonry fsy As Single 'Design stress of steel Height As Single 'Total height of wall/Length of Footing (sorry it is confusing) Height190 As Single 'Height of 190 blockwork Height290 As Single 'Height of 290 blockwork Moment25 As Single 'moment 25% from the top Moment50 As Single 'Moment 50% from the top Moment75 As Single 'Moment 75% from the top Phi As Single 'Capacity reduction factor Spacing As Single 'Bar Spacing X As Single 'Distance of resultant vertical force (Rotation Check) End Type Dim Wall As Blockwall Dim Footing As Blockwall 

和Subroutine的代码片段,其中给出了一个可变的Footing.Depth值(注意,这只是一个赋值的位置):

 Public Sub DrawWall(fLength As Single, fHeight As Single, kLength As Single, kHeight As Single, _ wHeight As Single, distToKey As Single, distToWall As Single, fBeta As Single, fPhi As Single, _ fDensity As Single, nBeta As Single, nPhi As Single, nDensity As Single, LL As Single, Height290 As Single) '***---ASSIGN VALUES TO GLOBAL VARIABLES---*** Footing.Depth = fHeight Footing.Height = fLength 

其他子画面调用子画板绘制所需的形状。 当DrawWall被调用时,只有当我点击一个调用子程序的button时(或者我从代码编辑窗口中启动子程序),似乎没有重设值。

事实certificate,创build和删除OLEObjects(用作input框)导致全局variables重置,一旦包含这些命令的子例程完成。 (非常感谢@Roryfind那个)。不幸的是,直到你开始下一个子程序(我不知道为什么),监视窗口才会更新值。 我可能会考虑使用类而不是types,以便variables存储不pipe。

感谢大家的帮助!