Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Waiting for process completion
#1
This script just blows through the lock which is only supposed to let execution continue if the process handle does not exist. I have tried "WP" "-WC" and "-WE". If you can do this what are the magic words or concept?

int h3=run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE");wait 15 p
int w2=act(win("Document1 - Microsoft Word" "OpusApp"))
lef 574 44 w2
mes "onereporter lock"
wait 0 -WE h3
mes "end onereporter lock"

Thanks
BTW Love the concept and the flexibility of the implementation - head and shoulders above the others surveyed
#2
run returns process handle. It is different than window handle. You can use various methods to wait until program exits:

Code:
Copy      Help
;Waiting for process handle
int h3=run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE");wait 15 p
int w2=act(win("Document1 - Microsoft Word" "OpusApp"))
lef 574 44 w2
mes "onereporter lock"
wait 0 H h3
CloseHandle h3
mes "end onereporter lock"

;Waiting for window's program exit (internally it is almost the same as above)
run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE");wait 15 p
int w2=act(win("Document1 - Microsoft Word" "OpusApp"))
lef 574 44 w2
mes "onereporter lock"
wait 0 WP w2
mes "end onereporter lock"

;Getting window handle and waiting until it is closed
int w1
run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE" "" "" "" 0 "Word" w1)
lef 574 44 w1
mes "onereporter lock"
wait 0 -WC w1
mes "end onereporter lock"

;Combined 2 and 3. This is probably the best.
int w1
run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE" "" "" "" 0 "Word" w1)
lef 574 44 w1
mes "onereporter lock"
wait 0 WP w1
mes "end onereporter lock"
#3
THanks for the reply - I tried most of the alts suggested but none so far have solved the problem. The code below is the smallest example. As it says in the comment, it seems to ignore waits on handles, any type of wait on any handle.

Would the code snippet work on your machine? Calling a Word macro from the menu?

Is there a way of calling the Word menu directly?

Can you suggest a method of creating a lock before the Word section executes and having the Word code gobble it up?

Thanks


int w4
run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE" "" "" "" 0 "Word" w4)
; wait 0 WA w4 - blows by this statement
wait 2
lef 441 47 w4
mes "filedialog lock"
;wait 0 WP w4 - ignores this statement
mes "filedialog unlock"
#4
The second question should read - "Is there any way of calling the Word macro directly?"
#5
I'm sorry - I gave the wrong information about what worked and what did not. The following program is a correct example. The program won't work w/o a "wait 2". Neither WA nor WV text for the existance of the Word top menu. Is there a way of testing for this or calling a Word macro directly?

Thanks

int w4
run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE" "" "" "" 0 "Word" w4)
wait 0 WA w4
;wait 2
lef 441 47 w4
;mes "filedialog lock"
wait 0 WP w4
;mes "filedialog unlock"
#6
On lef 441 47 w4, it opens a dialog, and then macro should wait until the dialog is closed?

I would better help you if you would describe exacly what is the purpose of the macro, and every step it should do.
#7
Ginteras,
Thanks for sticking with me through this - I take it you need a general functional desription.

Procedure
1. If the "RD" file is open as a window, then put filename into a file called heehaw.txt.
2. Call a Word macro to use the file dialog method to get the filename
3. Run a Word macro which reformats the "RD" file to an "SR" file
4. QM opens both RD and SR files (horizontally tiled) and runs a macro which highlights any errors in the RD file

Notes:
The Word macros are set up in the Word main menu bar, however, if there were a way of calling them directly i.e. normal.XMLLib.FileDialog that would be better. Alternatively - do I have to produce a dialog window at the start and end of every Word macro which I would use to synchronize processing?

Thanks, Bob

CheckNOpen Macro
Program wriiten 04-may-05 by Bob Arnold

Inputs
Open "RD" window
File dialog prompt

Outputs
d:\heehaw.txt containing
"RD" file name selected
d:\gobble.txt containing
full "RD" file name selected
SR report file
d:\errmsg.txt containing
error message from report processing if error occurs
d:\errcontext.txt containing
error context from report processing if error occurs
error highlighted in RD file if error occurs

Description
If an "RD" file is open then run the Reporter and re-display files
Else select file from file open dialog run Reporter and re-
display files

Pseudocode
if RD window open get full filename, run report and re-display
else prompt for file name, run report and re-display

Called by
QB

Calls
OneOpener (Microsoft Word)
#8
I did not find any Word functions to call Word macros directly.

Another way to synchronize Word and QM - at the end of the Word macro start QM macro. This example calls QM macro "QmMacroFromWord":

Shell "qmcl.exe M " & Chr(34) & "QmMacroFromWord" & Chr(34)

That is, use two QM macros. The first macro calls the Word macro (clicks Word toolbar button) and exits immediately. When the Word macro finishes, it calls the second QM macro.

Note that two QM macros cannot run simultaneously. The first macro must exit as soon as possible, or the second macro may not start. Tip: in second macro Properties, select Priority: wait. Or, use functions instead.
#9
Ginteras,

Thanks for your help on this. I may try it or I may try to implement the more general ooncept of a session lock.

It seems that other languages have this problem too (no session lock). I attach an excerpt from http://www.codeproject.com/threads/WsSessionLock.asp

Regards, Bob

Session Lock

A session lock is very useful especially when enumerating or iterating through all the elements in a collection. Fortunately, the .NET collection classes support the concept of a session lock. Here is an illustration:

// create a synchronized version of a collection object
ArrayList list = ArrayList.Synchronized( new ArrayList() );

// fill it with elements
for(int i=0; i<20; i++)
list.Add( new BankAccount() );

// inside a thread procedure
int num = 0;
lock(list.SyncRoot) // this is a session lock
{
double Sum=0;
IEnumerator enm = list.GetEnumerator();
while(enm.MoveNext())
Sum += ((BankAccount)enm.Current).Balance;

Console.Out.WriteLine("Sum: {0}", list.Count, num);
}

Every .NET collection class has this SynRoot member. If a lock is applied on this member, then every other thread is prevented from modifying the collection. No elements inside the collection can be removed or even modified. And no elements can be added to that collection. The SyncRoot is really a very good feature. But it is only available with the collection classes.

Nevertheless, we can provide session lock capabilities to any class of our own design with just a few lines of code. Unlike Java, the .NET framework provides us with a Monitor object which is a kind of critical section or mutex. Let us rewrite the BankAccount class in C#.

public class BankAccount {
private double _amount;

// the account methods
public void deposit(double amount) {
lock(this) {
_amount += amount;
}
}
public void withdraw(double amount) {
lock(this) {
_amount -= amount;
}
}
public double Balance {
get {
lock(this) {
return _amount;
}
}
}


// here are the session lock methods
public lock() {
Monitor.Enter(this);
}
public unlock() {
Monitor.Exit();
}
#10
Perhaps I could use the following in a QM routine which waits on a lock count of zero

var.lock
Locks array (increments lock count). If lock count is nonzero, array cannot be resized or destroyed (for example, by other threads or applications). Calls to lock can be nested. An equal number of calls to unlock are required. Failing to unlock causes memory leak.

var.unlock
Decrements lock count.

I would just shell out to an QM unlock in the Word macro using the formula
#11
The answer to the question - can I call a Word macro directly is ---

IDispatch app._create("Word.Application")
app.Visible = 0
app.run("normal.XMLLib.FileDialog")

--quite a powerfull language -- I'm not sure if I need the "session lock" now.
#12
How I did not find that Run...

The same using type library:

Code:
Copy      Help
typelib Word {00020905-0000-0000-C000-000000000046} 8.0

Word.Application a._create
a.Documents.Add
a.Visible=TRUE

a.Run("Test")

The same using VBScript:

Code:
Copy      Help
lpstr vbscode=
;Set a=CreateObject("Word.Application")
;a.Documents.Add
;a.Visible=True
;a.Run("Test")

VbsExec vbscode


Forum Jump:


Users browsing this thread: 1 Guest(s)