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 / 13list02.txt < prev    next >
Text File  |  1995-08-03  |  3KB  |  75 lines

  1. ' Listing 13LIST02.TXT
  2. ' Automatically adjust the control to fit the object.
  3.              OLE1.SizeMode = vbOLESizeAutosize
  4.              ' Display the Insert Object dialog 
  5.              ' to get an object to display.
  6.         ' Show FileOpen dialog to get a file to open.
  7.              CommonDialog1.FileName = "*.*"
  8.              CommonDialog1.ShowOpen
  9.              ' Check if file exists before creating link 
  10.              ' (see Function below).
  11.         If FileExists(CommonDialog1.FileName) Then
  12.              Attempt to create an embedded object.
  13.             OLE1.CreateLink CommonDialog1.FileName
  14.              End If
  15. '             OLE1.InsertObjDlg     
  16.           End Sub
  17. ' Checks if a file exists (uses full path and file name).
  18. Function FileExists(strFileName) As Boolean
  19.      ' Turn on error checking.
  20.      On Error Resume Next
  21.      ' FileLen causes error if file doesn't exist.
  22.      FileLen (strFileName)
  23.      If Err Then
  24.           FileExists = False
  25.           Err = 0
  26.      Else
  27.           FileExists = True
  28.      End If
  29.      ' Turn off error checking.
  30.      On Error GoTo 0
  31. End Function
  32.  
  33. Private Sub HScroll1_Change()
  34.               OLE1.Left = 0 - HScroll1.Value
  35.           End Sub
  36.  
  37.           Private Sub VScroll1_Change()
  38.               OLE1.Top = 0 - VScroll1.Value
  39.           End Sub
  40. Private Sub OLE1_Resize(HeightNew As Single, 
  41.                WidthNew As Single)
  42.               If HeightNew > Form1.Height Then
  43.                   VScroll1.Visible = True
  44.                   VScroll1.Max = HeightNew
  45.                   VScroll1.LargeChange = _
  46.                        HeightNew / (HeightNew / OLE1.Height)
  47.                   VScroll1.SmallChange = VScroll1.LargeChange / 10
  48.               Else
  49.                   VScroll1.Visible = False
  50.               End If
  51.               If WidthNew > Form1.Width Then
  52.                   HScroll1.Visible = True
  53.                   HScroll1.Max = WidthNew
  54.                   HScroll1.LargeChange = WidthNew / _
  55.                       (WidthNew / OLE1.Width)
  56.                   HScroll1.SmallChange = HScroll1.LargeChange / 10
  57.               Else
  58.                   HScroll1.Visible = False
  59.               End If
  60.           End Sub
  61. Private Sub Form_Resize()
  62.               ' Skip first Resize on Load.
  63.               Static bFlag As Boolean
  64.               If bFlag Then
  65.                   ' If form resizes, trigger OLE control
  66.                   '  resize behavior.
  67.                   OLE1_Resize OLE1.Height, OLE1.Width
  68.               Else
  69.                   bFlag = True
  70.               End If
  71.                ' Call support procedure to adjust the placement
  72.                ' and size of scroll bars on the form.
  73.                AdjustScrollBars Me
  74.           End Sub
  75.