home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / PGUIDE / OLECONT / OLECONT.BAS < prev    next >
Encoding:
BASIC Source File  |  1996-10-15  |  4.9 KB  |  134 lines

  1. Attribute VB_Name = "ModOLECont"
  2. Option Explicit
  3.  
  4. Public MDINew As Integer
  5.  
  6. Sub NewObject()
  7.     MDINew = True
  8.     NewOleForm
  9.     If ParentForm.ActiveForm.OLE1.OLEType = vbOLENone Then
  10.         Unload ParentForm.ActiveForm
  11.     End If
  12. End Sub
  13.  
  14. Sub DisplayInstructions()
  15.     ' Declare local variables.
  16.     Dim MsgText
  17.     Dim PB
  18.     ' Initialize the paragraph break variable.
  19.     PB = Chr(10) & Chr(13) & Chr(10) & Chr(13)
  20.     ' Display the instructions.
  21.     MsgText = "To insert a new object, choose New from the File menu, and then select an object from the Insert Object dialog box."
  22.     MsgText = MsgText & PB & "Once you have saved an inserted object using the Save As command, you can use the Open command on the File menu to view the object in subsequent sessions."
  23.     MsgText = MsgText & PB & "To edit an object, double-click the object to display the editing environment for the application from which the object originated."
  24.     MsgText = MsgText & PB & "Click the object with the right mouse button to view the object's verbs."
  25.     MsgText = MsgText & PB & "Use the Copy, Delete, and Paste Special commands to copy, delete, and paste objects."
  26.     MsgText = MsgText & PB & "Choose the Update command to update the contents of the insertable object."
  27.     MsgBox MsgText, 64, "OLE Container Control Demo Instructions"
  28. End Sub
  29.  
  30. Sub NewOleForm()
  31.     Dim Newform As New ChildForm
  32.     Newform.Show
  33.     ' Only display the Insert Object dialog box if the user chose New from the File menu.
  34.     If MDINew Then
  35.         ParentForm.ActiveForm.OLE1.InsertObjDlg
  36.     End If
  37.     
  38.     UpdateCaption
  39. End Sub
  40.  
  41. Sub OpenObject()
  42.     MDINew = False
  43.     NewOleForm
  44.     OpenSave ("Open")
  45.     If ParentForm.ActiveForm.OLE1.OLEType = vbOLENone Then
  46.         Unload ParentForm.ActiveForm
  47.     End If
  48. End Sub
  49.  
  50. ' Opening a new file will only work with a file that contains a valid OLE Automation object.
  51. ' To see this work, follow this procedure while the application is running.
  52. ' 1) From the File menu, choose New, and then specify an object.
  53. ' 2) Edit the object, and then choose Save As from the File menu.
  54. ' 3) Click the menu-control box for the object to close it.
  55. ' 4) From the File menu, choose Open, and then select the file you just saved.
  56. Sub OpenSave(Action As String)
  57.     Dim Filenum
  58.     Filenum = FreeFile
  59.     ' Set the common dialog options and filters.
  60.     ParentForm.ActiveForm.CommonDialog1.Filter = _
  61.       "Insertable objects (*.OLE)|*.OLE|All files (*.*)|*.*"
  62.     ParentForm.ActiveForm.CommonDialog1.FilterIndex = 1
  63.   
  64.     ParentForm.ActiveForm.OLE1.FileNumber = Filenum
  65.  
  66. On Error Resume Next
  67.  
  68.     Select Case Action
  69.         Case "Save"
  70.             ' Display the Save As dialog box.
  71.             ParentForm.ActiveForm.CommonDialog1.ShowSave
  72.             If Err Then
  73.                 ' User chose Cancel.
  74.                 If Err = 32755 Then
  75.                     Exit Sub
  76.                 Else
  77.                     MsgBox "An unanticipated error occurred with the Save As dialog box."
  78.                 End If
  79.             End If
  80.             ' Open and save the file.
  81.             Open ParentForm.ActiveForm.CommonDialog1.filename For Binary As Filenum
  82.             If Err Then
  83.                 MsgBox (Error)
  84.                     Exit Sub
  85.             End If
  86.                 ParentForm.ActiveForm.OLE1.SaveToFile Filenum
  87.             If Err Then MsgBox (Error)
  88.  
  89.         Case "Open"
  90.             ' Display File Open dialog box.
  91.             ParentForm.ActiveForm.CommonDialog1.ShowOpen
  92.             If Err Then
  93.                 ' User chose Cancel.
  94.                 If Err = 32755 Then
  95.                     Exit Sub
  96.                 Else
  97.                     MsgBox "An unanticipated error occurred with the Open File dialog box."
  98.                 End If
  99.             End If
  100.             ' Open the file.
  101.             Open ParentForm.ActiveForm.CommonDialog1.filename For Binary As Filenum
  102.             If Err Then
  103.                 Exit Sub
  104.             End If
  105.             ' Display the hourglass mouse pointer.
  106.             Screen.MousePointer = 11
  107.             ParentForm.ActiveForm.OLE1.ReadFromFile Filenum
  108.             If (Err) Then
  109.                 If Err = 30015 Then
  110.                     MsgBox "Not a valid object."
  111.                 Else
  112.                     MsgBox Error$
  113.                 End If
  114.                 Unload ParentForm.ActiveForm
  115.             End If
  116.             ' If no errors occur during open, activate the object.
  117.             ParentForm.ActiveForm.OLE1.DoVerb -1
  118.  
  119.         ' Set the form properties now that the OLE container control contains an object.
  120.         UpdateCaption
  121.         ' Restore the mouse pointer.
  122.         Screen.MousePointer = 0
  123.     End Select
  124.   
  125.     Close Filenum
  126. End Sub
  127.  
  128. Sub UpdateCaption()
  129.     ' Set the form properties now that it contains an object.
  130.     ParentForm.ActiveForm.Caption = ParentForm.ActiveForm.OLE1.Class + " Object"
  131.     On Error Resume Next
  132. End Sub
  133.  
  134.