Form_Load()不允许子执行VB6

时间:2016-07-15 11:58:34

标签: vb6

在处理vb6项目时,我发现无法使用form_load()执行sub(包含在外部模块中)。这是代码的样子:

Private Sub Form_Load()

ExampleSubroutine

End Sub

当时,我通过使用form_activate()代替启动表单来规避这个问题:

Private Sub form_activate()

ExampleSubroutine

End Sub

但是,这意味着只要程序切换到不同的表单并返回到主表单,子程序就会再次运行。我不想要这个。有没有办法使用form_load()执行sub?感谢。

1 个答案:

答案 0 :(得分:2)

可能是因为PictureBox尚未完全加载。使用Activate事件的一种方法是使用静态布尔值,然后在第一次触发时设置它。

Private Sub Form_Activate()

Static BeenHere as Boolean

If Not BeenHere Then
    ExampleSub
    BeenHere = True
End If

End Sub