执行Visual Basic程序能不能实现程序的等待和挂起。
就是这样的场景:
Public Function MainFun()
Call Fun1
Call Fun2
End Function
Public Function Fun1()
Dim Color As Long
For i=0 to 3000
For j=0 to 3000
Color=Picture1.Point(i,j)
Next
Next
End Function
Public Function Fun2()
Form1.Print "显示信息。"
End Function
就是我有什么办法,设置主程序MainFun(),让代码实现以下的效果:
一、由于调用的第一个函数Fun1较复杂,运行的时间较多,怎样让Fun1程序转到后台执行,不影响我继续运行Fun2。也就是在Fun1在后台运行的时候,我们运行了Fun2,并且在Fun1运行过程中就运行完了Fun2。
二、能不能将Fun1先挂起,先执行完较易执行Fun2,然后让Fun1继续执行。
答案最好在一个窗体内实现。最好不要让程序无响应、死机。
请帮忙解答以下,能给现金的。
有两种方法实现,有帮助望采纳:
方法1:在fun1的多次循环间隙中直接调用fun2;
Public Function Fun1()
Dim Color As Long
For i=0 to 3000
For j=0 to 3000
Color=Picture1.Point(i,j)
Next
call fun2
Next
End Function
方法2:通过定时器等在闲暇时间执行fun2.可以加一个定时器,在定时器事件中
call fun2
然后在fun1中加入消息处理:
Public Function Fun1()
Dim Color As Long
For i=0 to 3000
For j=0 to 3000
Color=Picture1.Point(i,j)
Next
doevents
Next
End Function
Fun1的循环中加一句DoEvents。这个语句是把控制权交给系统,不让程序卡死。