VB, shell and wordpad

       I created a program that creates a file and shells a copy of
wordpad so the the user can edit or print the data. After shelling
wordpad I must return back to processing within the program therefore I
cannot wait until wordpad has finished. If the operator presses this
button again I will again try to create a file and again try to start
wordpad. If the program is run inside of Win3.1 I get an error that I
can trap on but if it run in Win 95 all bets are off!!! 95 actually
allows me to do anything I want with the file but won't tell me that
wordpad is already using it. The problem is that I create the new file
and then try to start a new instance of wordpad. I get no indication
that it didn't work but there is only the original wordpad running with
the original file. Is there some way I can determine if someone is
already using this file in VB4.0 and Win95 so that I could start up
another copy of wordpad possibly with another filename?  Sorry the
description is so long but I wanted to give you as much info as
possible.

dougdjlAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

milton042297Commented:
Use this:
result& = VerInstallFile&(0, SrcFilename$, DestFileName$, SourcePath$, DestinationPath$, CurrDir$, TmpFile$, lpwTempFileLen%)

"VerInstallFile" is a API function, and "result&" is the return, and you can make a comparation like this:

****************************************************************
If (result& And VIF_FILEINUSE&) = VIF_FILEINUSE& Then
      X% = MsgBox("The file is aready in use, close all the            aplications and try again.", 34)
If X% = 3 Then
       CopyFile = False
ElseIf X% = 4 Then
       TryAgain% = True
       GoTo TryToCopyAgain
ElseIf X% = 5 Then
        CopyFile = True
        GoTo SkipThisFile
End If

*********************************************************

Search in "Win31wh.hlp" help file and Apilod16.exe program on "vb\winapi" directory for more details.

That's all, good luck.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dougdjlAuthor Commented:
I've tried the code and I am unable to load the version.dll in Win95. This function call is not available in Win31. Is this true? Any ideas about why I can't load the dll? It is dated 7-11-95. I get a runtime error 48. If you need the code let me know.
0
milton042297Commented:
use this:
Declare Function VerInstallFile Lib "ver.dll" (ByVal Flags%, ByVal SrcName$, ByVal DestName$, ByVal SrcDir$, ByVal DestDir$, ByVal CurrDir As Any, ByVal TmpName$, lpTmpFileLen&) As Long

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

dougdjlAuthor Commented:
Here's my code. It compiles and runs now(thanks) but it still doesn't tell me if the file (Test.Fil) is in use by wordpad. See if I did anything wrong.

Milton, thanks again for all your help.
p.s. this is only a dummy program. the real one is too much to send.

On a blank form create a text box and a command button.

Declare Function VerInstallFile Lib "ver.dll" (ByVal Flags%, ByVal SrcName$, ByVal DestName$, ByVal SrcDir$, _
                  ByVal DestDir$, ByVal CurrDir As Any, ByVal TmpName$, lpTmpFileLen&) As Long
Public Const VIF_FILEINUSE = &H80&

Function OkToOpenFile(TestFile As String, TestPath As String) As Boolean
Dim lpwTempFileLen As Long
    SrcFilename$ = TestFile
    DestFileName$ = TestFile
    SourcePath$ = TestPath
    DestinationPath$ = TestPath
    CurrDir$ = App.Path

   
    result& = VerInstallFile(0, SrcFilename$, DestFileName$, SourcePath$, DestinationPath$, CurrDir$, _
                    Tmpfile$, lpwTempFileLen)
    OkToOpenFile = True

    If (result& And VIF_FILEINUSE&) = VIF_FILEINUSE& Then
        X% = MsgBox("The file is aready in use, close all the aplications and try again.", 34)
        OkToOpenFile = False
    End If
End Function

Private Sub Command1_Click()
Dim ExecuteString As String
Dim RetVal As Variant
Dim TestResult As Boolean
Dim TestFile As String
   
    TestFile = "Test.Fil"
    If OkToOpenFile(TestFile, App.Path) Then
        TestFile = App.Path + "\Test.Fil"
        Open TestFile For Output As #1
        Write #1, Text1.Text
        Close #1
        ExecuteString = "Write " + TestFile
        RetVal = Shell(ExecuteString, vbNormalFocus)
    Else
        MsgBox ("File In Use")
    End If

End Sub
0
milton042297Commented:
use the backlask ("\") at the end of the Path string.
ex.:

*********************************************************
Dim Path as string

Path = App.Path
if Right$(Path,1) <> "\" then
    Path = Path + "\"
end if
' now is your code, look the Path variable, is diferent now.

If OkToOpenFile(TestFile, Path) Then
etc
etc
etc
.
.
.
.



0
milton042297Commented:
Hello dougdjl, how did you think about this ?
0
milton042297Commented:
Hello dougdjl, how did you think about this ?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.