Results 1 to 8 of 8

Thread: [RESOLVED] wait for file to be created

  1. #1

    Thread Starter
    Frenzied Member litlewiki's Avatar
    Join Date
    Dec 2005
    Location
    Zeta Reticuli Distro:Ubuntu Fiesty
    Posts
    1,162

    Resolved [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:
    1. Do While Not FileExists(App.Path & "\a22.htm")
    2.     DoEvents
    3.     Sleep (500)
    4. Loop
    5.  
    6. Public Function FileExists(Filename As String) As Boolean
    7. Set fso = New FileSystemObject
    8.  
    9. If fso.FileExists(Filename) Then
    10.     FileExists = True
    11. Else
    12.     FileExists = False
    13. End If
    14. End Function

    but still the error repeats .how do i make the second function wait for the file to be created

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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"

  3. #3

    Thread Starter
    Frenzied Member litlewiki's Avatar
    Join Date
    Dec 2005
    Location
    Zeta Reticuli Distro:Ubuntu Fiesty
    Posts
    1,162

    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

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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"

  5. #5

    Thread Starter
    Frenzied Member litlewiki's Avatar
    Join Date
    Dec 2005
    Location
    Zeta Reticuli Distro:Ubuntu Fiesty
    Posts
    1,162

    Re: wait for file to be created

    VB Code:
    1. Public Sub cf2(ByVal strInFileName As String)
    2.                
    3. Dim strInFileContent As String
    4. Dim strOutFileContent As String
    5. Dim i As Long, j As Long
    6. fileconv = True
    7. Open strInFileName For Input As #1
    8. Do Until EOF(1)
    9.     Line Input #1, strInFileContent
    10.     strOutFileContent = ""
    11.     j = 1
    12.     For i = 1 To Len(strInFileContent)
    13.         If Asc(Mid(strInFileContent, i, 1)) = 10 Then
    14.             strOutFileContent = strOutFileContent & vbCrLf
    15.             j = j + 2
    16.         Else
    17.             strOutFileContent = strOutFileContent & Mid(strInFileContent, i, 1)
    18.             j = j + 1
    19.         End If
    20.     Next
    21. Loop
    22. Close #1
    23. Kill (strInFileName)
    24.  
    25. tempstr = strOutFileContent
    26. fileconv = False
    27. End Sub
    28.  
    29.  
    30. Public Function ps2(Filename As String)
    31.  
    32. On Error GoTo err:
    33. j = 0
    34.  
    35.  
    36. 'Do While Not FileExists(App.Path & "\a22.htm")
    37. '    DoEvents
    38. '    Sleep (500)
    39. 'Loop
    40.  
    41.  
    42. 'Main_Page.WebBrowser1.Navigate2 App.Path & "\a22.htm"
    43.  
    44. Main_Page.WebBrowser1.Navigate "about:" & tempstr
    45.  
    46.  
    47. Do While blnBusy
    48.     DoEvents
    49.     Sleep (500)
    50. Loop
    51.  
    52. strdata = Main_Page.WebBrowser1.Document.body.innerhtml
    53.  
    54. 'function stmts here
    55.  
    56. tempstr = ""
    57.  
    58. Exit Function
    59.  
    60. err:
    61.  
    62.     Main_Page.lblmsg.Caption = "Error Retreiving messages,Please try after sometime"
    63.  
    64. End Function
    65.  
    66. this is how i call them
    67.  
    68.     lblmsg.Caption = "Analyzing..."
    69.     'Call ConvertFile(App.Path & "\a2.htm", App.Path & "\a22.htm")
    70.     Call cf2(App.Path & "\a2.htm")
    71.    
    72.     lblmsg.Caption = "Calculating..."
    73.     Call ps2(App.Path & "\a22.htm")

    it works in debug mode but in run time it gets stuck again

  6. #6

    Thread Starter
    Frenzied Member litlewiki's Avatar
    Join Date
    Dec 2005
    Location
    Zeta Reticuli Distro:Ubuntu Fiesty
    Posts
    1,162

    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...

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: wait for file to be created

    To speed this up a LOT:
    VB Code:
    1. Public Function cf2(ByVal strInFileName As String) As String
    2. Dim s As String
    3.  
    4.   Open strInFileName For Input As #1
    5.   s = Input(LOF(1), 1)
    6.   Close #1
    7.  
    8.   cf2 = Replace(s, vbLf, vbNewLine)
    9. End Function
    Then simply
    VB Code:
    1. ps2 cf2(App.Path & "\a22.htm")
    where ps2 is
    VB Code:
    1. Public Sub ps2(Filename As String)
    2.  
    3. On Error GoTo err:
    4. Main_Page.WebBrowser1.Navigate "about:" & Filename
    5. ...
    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

  8. #8

    Thread Starter
    Frenzied Member litlewiki's Avatar
    Join Date
    Dec 2005
    Location
    Zeta Reticuli Distro:Ubuntu Fiesty
    Posts
    1,162

    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
  •  



Click Here to Expand Forum to Full Width