สอบถามการ stop application ของ ontime ครับ
Posted: Wed Sep 13, 2023 5:45 am
background :
ผมสร้างชุดคำสั่ง ให้โปรแกรมอัพเดทเวลา อัตโนมัติ ทุกๆ 1 นาที โดยนำเวลาที่อัพเดทไปใช้ควบคู่กับระบบ PI system
แต่ปัญหาติดตรงที่ พอผมกด button(time_enable) เพื่อรันโปรแกรม โปรแกรม run ได้ปกติ, แต่พอกด button(time_disable) เพื่อหยุด ตัวโปรแกรมกลับไม่หยุดครับ
code :
Sub time_enable() 'assign button
timer1 = Now Application.OnTime timer1, "time_filling"
MsgBox ("Program Start")
End Sub
Sub time_filling() Worksheets("data").Range("B2").Value = Now StartTimeRecur
End Sub
Sub StartTimeRecur()
timer2 = Now + TimeValue("00:00:59") Application.OnTime timer2, "time_filling", , True End Sub
Sub time_disable() 'assign button
Application.OnTime timer2, "time_filling", , False MsgBox ("Program Stop")
End Sub
ผมสร้างชุดคำสั่ง ให้โปรแกรมอัพเดทเวลา อัตโนมัติ ทุกๆ 1 นาที โดยนำเวลาที่อัพเดทไปใช้ควบคู่กับระบบ PI system
แต่ปัญหาติดตรงที่ พอผมกด button(time_enable) เพื่อรันโปรแกรม โปรแกรม run ได้ปกติ, แต่พอกด button(time_disable) เพื่อหยุด ตัวโปรแกรมกลับไม่หยุดครับ
code :
Sub time_enable() 'assign button
timer1 = Now Application.OnTime timer1, "time_filling"
MsgBox ("Program Start")
End Sub
Sub time_filling() Worksheets("data").Range("B2").Value = Now StartTimeRecur
End Sub
Sub StartTimeRecur()
timer2 = Now + TimeValue("00:00:59") Application.OnTime timer2, "time_filling", , True End Sub
Sub time_disable() 'assign button
Application.OnTime timer2, "time_filling", , False MsgBox ("Program Stop")
End Sub