home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Programmer'…arterly (Limited Edition) / Visual_Basic_Programmers_Journal_VB-CD_Quarterly_Limited_Edition_1995.iso / code / ch13code / listings / 13list01.txt next >
Text File  |  1995-08-03  |  858b  |  30 lines

  1. ' File: 13LIST01.TXT
  2. Private Sub OLE1_DblClick()
  3.      ' Show FileOpen dialog to get a file to open.
  4.      CommonDialog1.FileName = "*.*"
  5.      CommonDialog1.ShowOpen
  6.      ' Check if file exists before creating link 
  7.      ' (see Function below).
  8.      If FileExists(CommonDialog1.FileName) Then
  9.           ' Attempt to create an embedded object.
  10.           OLE1.CreateLink CommonDialog1.FileName
  11.      End If
  12. End Sub
  13.  
  14. ' Checks if a file exists (uses full path and file name).
  15. Function FileExists(strFileName) As Boolean
  16.      ' Turn on error checking.
  17.      On Error Resume Next
  18.      ' FileLen causes error if file doesn't exist.
  19.      FileLen (strFileName)
  20.      If Err Then
  21.           FileExists = False
  22.           Err = 0
  23.      Else
  24.           FileExists = True
  25.      End If
  26.      ' Turn off error checking.
  27.      On Error GoTo 0
  28. End Function
  29.  
  30.