|
-
Aug 31st, 2011, 02:23 PM
#1
Thread Starter
New Member
Form freezes when I go back to it while program runs?
I have a program when started has a start and stop command button on it. As you can tell below, its opening that powerpoint file and sleeping for 236 minutes. After that it stops and closes, and runs updates in a loop and then reopens the powerpoint file for another 236 minutes.
My problem is when I go to click the stop button or even try to move or click anywhere on the form while the program runs, the program freezes. I think this is due to the sleep command. I need to be able to click on stop if I need to without it freezing. Does anyone have any suggestions to stop it from freezing? I ultimetly need it to stop at 236 minutes so it can close the powerpoint and go through the updates and then launches it again. I left out the other code that updates the files as it is not necessary to see it.
Thanks for any help!
====
PLEASE SEE 3rd message below
Last edited by zach campbell; Aug 31st, 2011 at 03:33 PM.
-
Aug 31st, 2011, 02:57 PM
#2
Re: Form freezes when I go back to it while program runs?
Instead of using Sleep which puts the program to sleep and so it's inactive, you could use a second timer with an interval of about half a second so it doesn't completely hog your resources. Also create a global boolean variable that you set to True in cmdStop and in the timer do
Code:
If bMyBoolean Then
Timer2.Enabled = False
End If
-
Aug 31st, 2011, 03:30 PM
#3
Thread Starter
New Member
Re: Form freezes when I go back to it while program runs?
This is the whole code, can you please add it in there so a person can be able to exit the power point presentation and be able to click close (which will reset the timer and stop the events without freezing).
When the timer resets at 240 minutes, it opens files which in turn updates the powerpoint presentation/slideshow and ultimetly displays it for 236 minutes.
Option Explicit
Private Minutes As Integer
Dim AccessApp As Object
Dim xlTmp As Excel.Application
Dim xlBook As Excel.Workbook
Dim oPPTApp As PowerPoint.Application
Dim oPPTPres As PowerPoint.Presentation
Dim SPresentationFile As String
Private Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
Private Sub cmdStart_Click()
Minutes = 0
Cls
Call DoWork
Timer1.Enabled = True
End Sub
Private Sub cmdStop_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.interval = 60000
End Sub
Private Sub Timer1_Timer()
Minutes = Minutes + 1
If Minutes = 240 Then
Minutes = 0
Call DoWork
End If
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub DoWork()
'Set AccessApp = CreateObject("access.Application")
'AccessApp.Visible = True
'AccessApp.OpenCurrentDatabase "I:\Inspectionsystem\Data\DWDATA2.mdb"
'AccessApp.DoCmd.RunMacro "SPC file updates"
'AccessApp.CloseCurrentDatabase
'AccessApp.Quit
'Set AccessApp = Nothing
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Set xlTmp = New Excel.Application
'Set xlBook = xlTmp.Workbooks.Open("I:\ISO Documents\QA\SPC Graphs\DD1.XLS")
'xlTmp.Visible = True
'xlBook.Close SaveChanges:=True
'Set xlBook = Nothing
'xlTmp.Quit
'Set xlTmp = Nothing
'Sleep 2000
'Set xlTmp = New Excel.Application
'Set xlBook = xlTmp.Workbooks.Open("I:\ISO Documents\QA\SPC Graphs\DD2.XLS")
'xlTmp.Visible = True
'xlBook.Close SaveChanges:=True
'Set xlBook = Nothing
'xlTmp.Quit
'Set xlTmp = Nothing
'Sleep 2000
'Set xlTmp = New Excel.Application
'Set xlBook = xlTmp.Workbooks.Open("I:\ISO Documents\QA\SPC Graphs\FP.XLS")
'xlTmp.Visible = True
'xlBook.Close SaveChanges:=True
'Set xlBook = Nothing
'xlTmp.Quit
'Set xlTmp = Nothing
'Sleep 2000
'Set xlTmp = New Excel.Application
'Set xlBook = xlTmp.Workbooks.Open("I:\ISO Documents\QA\SPC Graphs\PB-1.XLS")
'xlTmp.Visible = True
'xlBook.Close SaveChanges:=True
'Set xlBook = Nothing
'xlTmp.Quit
'Set xlTmp = Nothing
'Sleep 2000
'Set xlTmp = New Excel.Application
'Set xlBook = xlTmp.Workbooks.Open("I:\ISO Documents\QA\SPC Graphs\PB-3.XLS")
'xlTmp.Visible = True
'xlBook.Close SaveChanges:=True
'Set xlBook = Nothing
'xlTmp.Quit
'Set xlTmp = Nothing
'Sleep 2000
'Set xlTmp = New Excel.Application
'Set xlBook = xlTmp.Workbooks.Open("I:\ISO Documents\QA\SPC Graphs\SRH-012.XLS")
'xlTmp.Visible = True
'xlBook.Close SaveChanges:=True
'Set xlBook = Nothing
'xlTmp.Quit
'Set xlTmp = Nothing
'Sleep 3000
'''''''''''''''''''''''''''''''''''''
'Set xlTmp = New Excel.Application
'Set xlBook = xlTmp.Workbooks.Open("I:\ISO Documents\QA\SPC Graphs\spc summary graphs.xls")
'xlTmp.Visible = True
'xlTmp.Run ("pastetopowerpoint")
'xlBook.Close SaveChanges:=True
'Sleep 5000
'Set xlBook = Nothing
'Set xlTmp = Nothing
''''''''''''''''''''''''''''''''''''''
Dim intStop As Integer
SPresentationFile = "c:\zach.ppt"
Set oPPTApp = New PowerPoint.Application
oPPTApp.Visible = True
Set oPPTPres = oPPTApp.Presentations.Open(SPresentationFile)
oPPTPres.SlideShowSettings.Run
Sleep 14160000
oPPTPres.Close
oPPTApp.Quit
Set oPPTApp = Nothing
Set oPPTPres = Nothing
End Sub
Last edited by zach campbell; Aug 31st, 2011 at 03:36 PM.
-
Aug 31st, 2011, 03:38 PM
#4
Re: Form freezes when I go back to it while program runs?
Actually why don't you try this. I assume you can set up Timer2 with a short Interval to loop for the same amount of time as your Sleep code.
Code:
Private Sub cmdStop_Click()
Timer1.Enabled = False
Timer2.Enabled = False
DoEvents
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|