Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing the result???

Status
Not open for further replies.

jgoodman00

Programmer
Jan 23, 2001
1,510
I have the following code in a module, to check if a file exists:

Function CheckFileExists(ByVal IN_FILENAME As String) As Integer

Dim iresult As Integer
Dim strucFname As OFSTRUCT
Dim strSearchFile As String

strSearchFile = IN_FILENAME

iresult = OpenFile(strSearchFile, strucFname, OF_EXIST)

'The above line causes OpenFile to search for the
'file Test on the server network path.
'Passing the OF_EXIST parameter tells the OpenFile
'function to search for the file, the file will not be
'opened or modified in any way.

CheckFileExists = iresult

End Function

I then have the following code under a button in a form:
Private Sub VegGide_Click()
On Error GoTo Err_VegGide_Click

Dim stAppName As String

GeoOutlook:
If CheckFileExists("C:\Bentley\Program\GeoOutlook\geooutlk.exe") = True Then
stAppName = "C:\Bentley\Program\GeoOutlook\geooutlk.exe c:\gide\standard\work\gide.dgn -wdodbc"
ElseIf CheckFileExists("C:\Bentley\Program\GeoOutlook\geooutlk.exe") = False Then
GoTo Microstation
End If


Microstation:
If CheckFileExists("C:\WIN32APP\ustation\USTATION.EXE") = True Then
stAppName = "C:\WIN32APP\ustation\USTATION.EXE c:\gide\standard\work\gide.dgn -wdodbc -wustandard1"
ElseIf CheckFileExists("C:\WIN32APP\ustation\USTATION.EXE") = False Then
GoTo VegGide_Err
End If


VegGide_Err:
MsgBox "A Compatible viewer could not be found, press OK to continue", vbOKOnly
Exit Sub

Exit_VegGide_Click:
Exit Sub

Err_VegGide_Click:
MsgBox Err.Description
Resume Exit_VegGide_Click

End Sub


As you can see, the idea is that the function executes & returns either a true or a false. This part works, but for some reason the result just disappears before the next line of code can get it. Does anyone have any suggestions as to what my code should be???
James Goodman
 
This should be a much simpler way:

==========
Public Function FileExists(strFile As String) As Boolean
FileExists = Dir(strFile) <> &quot;&quot;
End Function
==========

==========
Private Sub VegGide_Click()
Dim strAppName As String

If FileExists(&quot;C:\Bentley\Program\GeoOutlook\geooutlk.exe&quot;) Then
strAppName = &quot;C:\Bentley\Program\GeoOutlook\geooutlk.exe c:\gide\standard\work\gide.dgn -wdodbc&quot;
Else
If FileExists(&quot;C:\WIN32APP\ustation\USTATION.EXE&quot;) Then
strAppName = &quot;C:\WIN32APP\ustation\USTATION.EXE c:\gide\standard\work\gide.dgn -wdodbc -wustandard1&quot;
Else
MsgBox &quot;A Compatible viewer could not be found, press OK to continue&quot;
End If
End If
End Sub
==========

You can use the FileExists function with a network drive as well

If FileExists(&quot;\\Stcnov01\data\reserved\db\opus\opus.mde&quot;) Then ....

Jim Lunde
compugeeks@hotmail.com
Custom Application Development
 
Thankyou, I got it working through the other one anyway, realising it wass returning an integer, &amp; more importantly i had ommited the shell command which actually made the program run!!! James Goodman
j.goodman00@btinternet.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top