|
-
Jul 13th, 2006, 01:36 PM
#1
Thread Starter
Frenzied Member
[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
-
Jul 13th, 2006, 01:51 PM
#2
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...
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 13th, 2006, 02:02 PM
#3
Thread Starter
Frenzied Member
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
-
Jul 13th, 2006, 02:08 PM
#4
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
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 13th, 2006, 03:26 PM
#5
Thread Starter
Frenzied Member
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
-
Jul 14th, 2006, 02:40 AM
#6
Thread Starter
Frenzied Member
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...
-
Jul 14th, 2006, 09:46 AM
#7
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
...
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Jul 14th, 2006, 12:41 PM
#8
Thread Starter
Frenzied Member
Re: wait for file to be created
oh yeah indeed thanks for that tip .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|