Click here to Skip to main content
14,211,379 members
Rate this:
Please Sign up or sign in to vote.
See more:
I'm trying to convert several documents to pdf via VB6. The documents are created by vb6 from a database and inserted into a report which I print using a pdf printer to a folder.

When I print a file I wish to move it and rename it to the correct filename. Got the code done to do so.

I've got a problem where the file isn't "printed" quick enough meaning I try to move a file which doesn't yet exist. I tried to sleep my program but that doesn't help, it seems the printing is done in the same thread as the program or something.

I've come up with several work arounds in my head but they all got their own problem. One was if I named the file differently then I could print one file, get the data and start printing the next one and then move back to the first one and do a move and rename. Basically trailing one print job all the time. But that is a no go atm because one problem is that I cant send an argument with what I want the filename to be. Bullzip which I use seems to take a window name as the filename, eg printing from notepad creates a file called notepad - openfile.pdf

My files gets named as MSDataReport.pdf. I'm curious if I can make this approach usable by getting the window using windows api?

The "best" results so far have been by adding a plain msgbox which pops up and then use a timed auto clicker to wait a few seconds and then press ok. It seems that the messagebox doesn't prevent the printing the same way as sleep does. This approach is risky and will lock my computer for the duration so it's not optimal either but atleast it saves me from a lot of manual labor.

Any thoughts on what I can do? Either improve my own solutions or other ways to work around this?
Posted
Comments
CHill60 30-Oct-15 9:38am
   
You could try multi-threading[^] - although it would be better if you used a .NET language rather than the moribund VB6
or wait for process to finish[^] before attempting the copy
Member 11683251 30-Oct-15 9:57am
   
Well this we are retiring this system in a month so I'll be from VB6 then. I was thinking about writing it in .net c# but getting the layout of the form right might be a hassle.

I was thinking about multithreading but I feel like it would be too much of a hassle for this task, will probably take so long to get it working that the time saved/extra spent wouldn't justify that approach.

Wait for process to finish seems to be exactly what I need, not sure if it will add a few extra seconds per file but if It allows me to leave my computer on over the weekend while it does the work it doesn't matter.

Going to run with that because it shouldn't take to long to implement. Thanks for the help. Much appreciated.
CHill60 30-Oct-15 10:04am
   
It will be more efficient than an arbitrary timer or sleep.
If you are planning to run this "unattended" then can I also suggest that you capture errors and log them then move onto the "next" file/report automatically - that way you have a list of problems to deal with on Monday morning rather than just the one (and then having to wait for the process to hit the next one) ;-)

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

OP has agreed that wait for process to finish[^] satisfies the requirement. Link contains full code snippet.

(I am not associated with the website!)
   
Comments
Member 11683251 30-Oct-15 10:20am
   
I have tested running a small span of files this way and it works perfectly for my purpose. Was already capturing errors, or so I thought but your last comment made me realize that I should probably do some testing so I deleted a file and then allowed the program to continue and found a small bug but after fixing it logs it nicely and continues. :)
CHill60 30-Oct-15 10:22am
   
Fantastic news! - you might have guessed I've been there before and come back after a weekend to find I needed to restart a process ;-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190619.1 | Last Updated 30 Oct 2015
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100