Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with taskexists

Status
Not open for further replies.

dbsquared

Programmer
Nov 7, 2002
175
US
I have code that I have written that loops through great without the taskexists command. Quick background: Code begins to execute then calls a function to open excel I then proceed to loop through again after excel is completed. I used a pause and that worked. When I have the taskexists it doesn't seem to recognize that excel is done all the time. It is very hit and miss which locks up the code and doesn't complete the entire program. I took the pause out because I don't want to have stuff like that hard coded if I can help it.

I have put a pause 1 in it and I have also cleared the variable I use to get the taskid for excel. I am using 95 and 2000 on 2 different machines. I have noticed I have many more issues with 2000 than 95 I have had to hard code some exiting commands because taskexit doesn't work with 2000.

Any help would be appreciated.
Thanks

Dan
 
Sure here it is


Proc OpenExcel
integer Excel_Num2

#define _Excel2 "C:\Program Files\Microsoft
Office\Office\EXCEL.EXE c:\msoffice\excel\Discomacro.xls"

if run _Excel2 Excel_Num2 ;MAXIMIZED
while !Excel_Num2
Yield
endwhile
else
statmsg "Excel did not run Properly"
exit
endif

while TASKEXISTS Excel_Num2
;termmsg "waiting for excel to close 'r'n"
pause 1
yield
endwhile
;termmsg "Excel has closed"

Excel_Num2 = 0
endproc

my excel code runs for a while then will close excel when completed.

 
forgot to add that when I clear the variable at the end that seems to work a lot better.
 
You can get rid of these lines:

while !Excel_Num2
Yield
endwhile

because the ! operator is going to perform a logical negation of the Excel task ID. In my case at least, the while loop exited immediately since the task ID was a negative integer which caused !Excel_Num2 to be zero. I don't know if your script could be getting stuck in this while loop, but this code is not needed since you are checking the task ID with the while taskexists command later in your script. aspect@aspectscripting.com
 
My script is locking up in this loop.

while TASKEXISTS Excel_Num2
;termmsg "waiting for excel to close 'r'n"
pause 1
yield
endwhile

I have tested it many times, it is getting stuck testing for Excel. The script will run fine but sometimes about the 30th or 40th time it will stop working.
I log into about 70 devices with the script.
To go where no programmer has gone before.
 
What happens if you remove the pause 1 from the loop? If you bring up the Task Manager or press Ctrl-Alt-Del, does it look like there is an Excel process running in the background, even though you do not see the UI?
aspect@aspectscripting.com
 
If I remove the pause 1 the script seems to lock up more frequently.
For the task manager there is nothing there. In my excel scripts Excel is shut down completely so that nothing is open.

For the code below I use it to make sure excel opens completely before moving to the next step in the code.

while !Excel_Num2
Yield
endwhile To go where no programmer has gone before.
 
I am using Excel 97 and 2002 To go where no programmer has gone before.
 
I only have Excel 2000, but hopefully that will be good enough to try to determine what is happening.

You mentioned that you are running something in Excel once it is loaded. If you just load the spreadsheet itself and no macros, etc. does it seem to behave better?
aspect@aspectscripting.com
 
In the script, wouldn't this staement:

if run _Excel2 Excel_Num2 ;MAXIMIZED

make the integer value of Excel_Num2 a One?

So that this statement:

while !Excel_Num2
Yield
endwhile
Would yield indefinitely, since the value of the integer that keeps it in yield state would not change without being evaluated again?
Robert Harris
 
This script worked like a charm every time before I put in the taskexists. I had a pause hardcoded in.
I didn't want to hard code in any type of time variables. I want to know when excel exits to go to the next section of code with out having to wait if not neccessary. To go where no programmer has gone before.
 
I take it that your main script calls the OpenExcel procedure numerous times while it is running?

One thing I would try doing is compiling a debug script then invoking the ASPECT debugger when the script appears locked up. To do so, open the ASPECT Editor and select the Tools | Compiler Options menu item. Check the Compile for debug box, click OK to close the dialog, and recompile your script. When your script appears to have locked up, press Ctrl-Break to bring up the debugger. The debugger will show you the currently executing command and you can then continue execution of your script using the Step or Continue buttons. Additionally you can view the values of the different variables you are using to see if they are what you would expect.
aspect@aspectscripting.com
 
I think that I have found part of the problem. Procomm is having an isuue with Norton antivirus. It locks up when it running however when I disable Norton it runs great. Also when I run McAfee antivirus it runs great also. It seems as though Norton is interfering with procomm. Is there a known issue with norton? To go where no programmer has gone before.
 
I'm not aware of any interactions with NAV, but I do know that past Norton software (such as shell replacements) and older versions of Procomm didn't like each other at times. Is it maybe because Norton is scanning that Excel spreadsheet on startup?
aspect@aspectscripting.com
 
I am still having issues wht the taskexists. Any suggestions? To go where no programmer has gone before.
 
If it still appears to be a conflict between NAV and Procomm, then I don't have any suggestions to offer, other than adding the file (or all XLS files) to NAV's exclusion list. The Norton support people at Symantec's forum may have some other ideas from the NAV side as well.
aspect@aspectscripting.com
 
I have NAV turned off and I am still having issues. To go where no programmer has gone before.
 
I encountered the same problem and I did find a work around that works fine in my case!

run "program.exe" progID
while $pwactive == 1
yield
endwhile

This pauses script execution as long as the procomm window running the script is active.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top