Solved

VB, shell and wordpad

Posted on 1997-04-29
7
473 Views
Last Modified: 2012-06-27
       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.

0
Comment
Question by:dougdjl
  • 5
  • 2
7 Comments
 
LVL 1

Accepted Solution

by:
milton042297 earned 180 total points
ID: 1425800
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
 

Author Comment

by:dougdjl
ID: 1425801
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
 
LVL 1

Expert Comment

by:milton042297
ID: 1425802
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:dougdjl
ID: 1425803
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
 
LVL 1

Expert Comment

by:milton042297
ID: 1425804
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
 
LVL 1

Expert Comment

by:milton042297
ID: 1425805
Hello dougdjl, how did you think about this ?
0
 
LVL 1

Expert Comment

by:milton042297
ID: 1425806
Hello dougdjl, how did you think about this ?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question