Solved

VB, shell and wordpad

Posted on 1997-04-29
7
470 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 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