Solved

VB, shell and wordpad

Posted on 1997-04-29
7
475 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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