Results 1 to 14 of 14

Thread: [RESOLVED] a race condition???

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    34

    Resolved [RESOLVED] a race condition???

    Hi

    I want to use a macro which generates a postscript file and then want to use this created file. For the example i have the folowing code, which first generates a ps file and call it (test.txt) and then wants to open it with notepad.exe.
    VB Code:
    1. Private Function doPS(nameofFile As String) As String
    2. '
    3.  
    4. '
    5.     Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
    6.         wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
    7.         ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
    8.         True, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
    9.         PrintZoomPaperHeight:=0, OutputFileName:=nameofFile, Append:=False
    10.        
    11.     doPS = nameofFile
    12. End Function
    13.  
    14. Sub test()
    15.     Dim f As String
    16.     'f = doPS("C:\test.txt")   '..................(1)
    17.     'f = "C:\test.txt"            '..................(2)
    18.     Shell "notepad.exe " & f
    19. End Sub

    When executing this macro on a .doc file (which contains some text): uncommenting (1): opens notepad with an empty file (so it does not considerate the generated file test.txt)
    now comment (1 ) and uncomment (2) (C:\text.txt exists!) and notepad opens the test.txt perfectly!

    I think it may be a synchronisation problem: shell() executes before doPS() finishes, I searched if there was a wait() function in VBA which waits until doPS() finishes and the Shell() begins...Is there a way to cure this problem? (of course I want to use one and only one macro to do these tasks! )

    thanx for reading this thread
    Last edited by waiso; Jun 26th, 2006 at 04:34 AM.

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