Re: Does anyone know how to write VB?
From: Larry Serflaten (serflaten_at_usinternet.com)
Date: 04/06/04
- Next message: Larry Serflaten: "Re: How do I scale a form so that I can print it out A4 size"
- Previous message: Douglas: "Re: VBKeyCodeEnd"
- In reply to: Eric: "Re: Does anyone know how to write VB?"
- Next in thread: Karl E. Peterson: "Re: Does anyone know how to write VB?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 6 Apr 2004 10:33:29 -0500
"Eric" <email@anon.com> wrote
> Requirement: VB Program to call external program. External program is
> PDF995 which creates a .pdf output file. The output file may not appear
> right away. Following the call, the VB program must rename the output file.
> PDF995 holds the output file open until it is finished writing. The file
> cannot be renamed until it is closed. VB apparently cannot sit and wait on
> the calling statement.
What is not obvious is why the PDF995 program does not save the file to
the proper name to begin with. Have you fully researched that option?
Does PDF995 close down when it has saved the file, or is that left running?
If it closes down, then the Shell and Wait method should do as you need.
But, rather than force VB to wait in a tight loop, I would suggest using a timer.
While your program is in a tight loop, the CPU meter goes to the top and the
whole program becomes unresponsive to user input.
Not so when you use a timer. It fires an event ever so often, and in between
events your program is free to do other things, like accept user input.
For an example, add a timer to a new form, and paste in the code below.
Set the path to something that will work on your system then start the
program. It will wait for the file to be created, and then rename it. While
it waits you are free to move the form around, and minimize it if you want.
Go to the path folder and create the file, then watch the forms caption to
see that it finishes, and refresh Explorer to see the new name.
HTH
LFS
Option Explicit
Const Path = "D:\temp\"
Const File = "RenameThis.txt"
Private Sub Form_Load()
' Kick off PDF995 and start timer
Timer1.Interval = 2000
Timer1.Enabled = True
Caption = "Waiting"
End Sub
Private Sub Timer1_Timer()
If FileExists(Path & File) Then
' Rename it
Name Path & File As Path & "Renamed.txt"
Timer1.Enabled = False
Caption = "Done"
End If
End Sub
Private Function FileExists(ByRef FileName As String) As Boolean
On Error Resume Next
FileExists = ((GetAttr(FileName) And vbDirectory) <> vbDirectory)
Err.Clear
End Function
- Next message: Larry Serflaten: "Re: How do I scale a form so that I can print it out A4 size"
- Previous message: Douglas: "Re: VBKeyCodeEnd"
- In reply to: Eric: "Re: Does anyone know how to write VB?"
- Next in thread: Karl E. Peterson: "Re: Does anyone know how to write VB?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|