[RESOLVED] wait for file to be created
i have a function that opens a file makes changes then saves it to another file
and after that another function that takes this newly created file as an input and parses it.
the problem is it takes time for first function to write out the file and by that time the second file raises an error that file doesnt exist...
so i put up a while loop like this
VB Code:
Do While Not FileExists(App.Path & "\a22.htm")
DoEvents
Sleep (500)
Loop
Public Function FileExists(Filename As String) As Boolean
Set fso = New FileSystemObject
If fso.FileExists(Filename) Then
FileExists = True
Else
FileExists = False
End If
End Function
but still the error repeats .how do i make the second function wait for the file to be created
Re: wait for file to be created
take out the "middle man"
do not write the file.. take the enitre data from the first file with the stuff you want changed... and pass it to the function that would parse it. dont write then re-read...
Re: wait for file to be created
its like there's a function(prior to these two) that dloads a file and saves it in unix format that is without the cr tags so i have to first replace all the cr with crlf on to another file(the first function) and then iam loading this file to a webbrowser control and parsing it(the second function) so i dont think removing the 'middleman' would solve the problem as i have to load the entire file on to the webbrowser control for it to work
Re: wait for file to be created
sure it would...
load the entire file into a variable...
do your replace.. good. now the variable still has the entire file in it..
Webbrowser.Navigate "about:" & FILEVARIABLE
if the file is an html or whatever.. then that will work..
or
webbrowser.navigate "about:blank"
then on the do complete event..
Webbrowser.Document.Write VARIABLE
Re: wait for file to be created
VB Code:
Public Sub cf2(ByVal strInFileName As String)
Dim strInFileContent As String
Dim strOutFileContent As String
Dim i As Long, j As Long
fileconv = True
Open strInFileName For Input As #1
Do Until EOF(1)
Line Input #1, strInFileContent
strOutFileContent = ""
j = 1
For i = 1 To Len(strInFileContent)
If Asc(Mid(strInFileContent, i, 1)) = 10 Then
strOutFileContent = strOutFileContent & vbCrLf
j = j + 2
Else
strOutFileContent = strOutFileContent & Mid(strInFileContent, i, 1)
j = j + 1
End If
Next
Loop
Close #1
Kill (strInFileName)
tempstr = strOutFileContent
fileconv = False
End Sub
Public Function ps2(Filename As String)
On Error GoTo err:
j = 0
'Do While Not FileExists(App.Path & "\a22.htm")
' DoEvents
' Sleep (500)
'Loop
'Main_Page.WebBrowser1.Navigate2 App.Path & "\a22.htm"
Main_Page.WebBrowser1.Navigate "about:" & tempstr
Do While blnBusy
DoEvents
Sleep (500)
Loop
strdata = Main_Page.WebBrowser1.Document.body.innerhtml
'function stmts here
tempstr = ""
Exit Function
err:
Main_Page.lblmsg.Caption = "Error Retreiving messages,Please try after sometime"
End Function
this is how i call them
lblmsg.Caption = "Analyzing..."
'Call ConvertFile(App.Path & "\a2.htm", App.Path & "\a22.htm")
Call cf2(App.Path & "\a2.htm")
lblmsg.Caption = "Calculating..."
Call ps2(App.Path & "\a22.htm")
it works in debug mode but in run time it gets stuck again
Re: wait for file to be created
it takes a long time to fill the tempstr variable or the temporary variable and by then the second function gets called ,so the problem persists...
Re: wait for file to be created
To speed this up a LOT:
VB Code:
Public Function cf2(ByVal strInFileName As String) As String
Dim s As String
Open strInFileName For Input As #1
s = Input(LOF(1), 1)
Close #1
cf2 = Replace(s, vbLf, vbNewLine)
End Function
Then simply
VB Code:
ps2 cf2(App.Path & "\a22.htm")
where ps2 is
VB Code:
Public Sub ps2(Filename As String)
On Error GoTo err:
Main_Page.WebBrowser1.Navigate "about:" & Filename
...
Re: wait for file to be created
oh yeah indeed thanks for that tip .