-
I'm writing a VB5 program in which I have to download data from the company's mainframe computer (in the form of .txt files) and then modify that data into a Access database. I can do everything but one thing- which is killing me.
When I Shell the program which begins to download the data from the mainframe to the local computer- I dont know when I can tell my vb program it's safe to continue. The size of the text file varies from month to month (its never the same size- so some months it could take seconds to download and other months it could take hours). I have to somehow make it so that VB recognises NOT when the file exists BUT WHEN THE FILE SIZE OF THE FILE STOPS CHANGING (therefore we know the file download is complete). I'm using the below code (please feel free to eithier modify it or provide a different code that would work). BTW- the file that I'm working with is "C:\rbsscs\cusms.txt"
Function FileDownloaded(FileName as String)
Dim tmrInterval&, X&,Y&
On Error Resume Next
X& = 1
Do While X& <> Y&
tmrInterval& = Timer
X& = FileLen("C:\rbsscs\cusms.txt")
Do Until Timer - tmrInterval& >= 5
DoEvents
Loop
Y& = FileLen("C:\rbsscs=cusms.txt")
Loop
Where in the above code is the best place can I add the code that is used once the file is done downloading (mainly the sendkeys funtion to exit out of the other download program)
PLEASE HELP,
PLEASE,
Brandr Beekman
[email protected]
-
NOTE: I'm sorry but after posting this code I found that it doesn't work. One problem is that either the function name should be changed to TestStillAlive or all the TestStillAlive references should be changed to TestIfProcessStillAlive, but even after doing that it still doesn't work. Can someone fix it?
============================================================
Here is some code that I picked up someplace.
Code:
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long
Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Public Function TestIfProcessStillAlive(ProcessID As Long) As Boolean
Dim Alive_ones As Long
Dim LoopTroughProcess As Long
Dim AlivePulse As Long
Dim hProcess As Long
Dim lngExitCode As Long
AlivePulse = 0
If ProcessID <> 0 Then
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessID)
If hProcess <> 0 Then
GetExitCodeProcess hProcess, lngExitCode
Else 'process not found
TestStillAlive = False
Exit Function
End If
'if you open a handle then you have to close it too
CloseHandle (hProcess)
Else
TestStillAlive = False
Exit Function
End If
If lngExitCode = 259 Then
TestStillAlive = True
Else
If lngExitCode = 0 Then TestStillAlive = False
End If
End Sub
To test if shelled process has finished use the code similar to this:
Code:
Dim Handle as long
Handle = shell("MyProgram.exe")
While not TestIfProcessStillAlive(Handle)
<code when process not finished>
wend
[Edited by MartinLiss on 07-31-2000 at 01:24 PM]
-
I am not sure if this may help on not, but here goes.
You are simply delaying for a time then checking for a change in size, right? Well if there is no change in size at the time of checking it does not mean the write is complete does it? There is no way of determining if there is going to to be more data written in the future?
There might be a way of checking if the file is closed. I assume the write functionallity keeps the file open for the duration of the write. If so use an API or something to check if the file has been released.
This is a different approach to the one you are using, but I cannot see the logic in checking for a change during an arbitrary time period, when there might be more write data to come.
Sorry for not giving you a solution, just food for thought.