home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / oledem / main.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  9.1 KB  |  306 lines

  1. VERSION 2.00
  2. Begin Form frmMain 
  3.    Caption         =   "Save and Load Ole Objects"
  4.    ClientHeight    =   3660
  5.    ClientLeft      =   525
  6.    ClientTop       =   2160
  7.    ClientWidth     =   8250
  8.    Height          =   4350
  9.    Left            =   465
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3660
  12.    ScaleWidth      =   8250
  13.    Top             =   1530
  14.    Width           =   8370
  15.    Begin Frame Frame2 
  16.       Caption         =   "Object Loaded"
  17.       Height          =   3375
  18.       Left            =   3120
  19.       TabIndex        =   3
  20.       Top             =   120
  21.       Width           =   4965
  22.       Begin OLE OLE1 
  23.          DisplayType     =   1  'Icon
  24.          fFFHk           =   -1  'True
  25.          Height          =   2415
  26.          Left            =   150
  27.          TabIndex        =   4
  28.          Top             =   690
  29.          Width           =   4665
  30.       End
  31.       Begin Label LabelUnsaved 
  32.          Caption         =   "*"
  33.          Height          =   255
  34.          Left            =   150
  35.          TabIndex        =   6
  36.          Top             =   390
  37.          Width           =   135
  38.       End
  39.       Begin Label LabelFormat 
  40.          Alignment       =   1  'Right Justify
  41.          Caption         =   "LabelFormat"
  42.          Height          =   255
  43.          Left            =   3240
  44.          TabIndex        =   5
  45.          Top             =   390
  46.          Width           =   1575
  47.       End
  48.       Begin Label LabelLoaded 
  49.          Caption         =   "LabelLoaded"
  50.          Height          =   255
  51.          Left            =   300
  52.          TabIndex        =   0
  53.          Top             =   390
  54.          Width           =   2955
  55.       End
  56.    End
  57.    Begin Frame Frame1 
  58.       Caption         =   "Objects in Database"
  59.       Height          =   3375
  60.       Left            =   120
  61.       TabIndex        =   1
  62.       Top             =   120
  63.       Width           =   2775
  64.       Begin ListBox ListObject 
  65.          Height          =   2760
  66.          Left            =   120
  67.          TabIndex        =   2
  68.          Top             =   360
  69.          Width           =   2535
  70.       End
  71.    End
  72.    Begin Menu mnuRecord 
  73.       Caption         =   "&Record"
  74.       Begin Menu mnuRecordLoad 
  75.          Caption         =   "&Load"
  76.       End
  77.       Begin Menu mnuRecordSave 
  78.          Caption         =   "&Save..."
  79.       End
  80.       Begin Menu mnuRecordDelete 
  81.          Caption         =   "&Delete"
  82.       End
  83.       Begin Menu mnuRecordSep1 
  84.          Caption         =   "-"
  85.       End
  86.       Begin Menu mnuRecordExit 
  87.          Caption         =   "&Exit"
  88.       End
  89.    End
  90.    Begin Menu mnuObject 
  91.       Caption         =   "&Object"
  92.       Begin Menu mnuObjectInsert 
  93.          Caption         =   "&Insert..."
  94.       End
  95.       Begin Menu mnuObjectDelete 
  96.          Caption         =   "&Delete"
  97.       End
  98.       Begin Menu mnuObjectEdit 
  99.          Caption         =   "&Edit"
  100.          Begin Menu mnuObjectVerb 
  101.             Caption         =   "verb"
  102.             Index           =   0
  103.          End
  104.       End
  105.    End
  106. Option Explicit
  107. Function DocumentFormatDescription (iType As Integer) As String
  108.     Select Case iType
  109.         Case 0
  110.             DocumentFormatDescription = "0 Access 1.x Ole"
  111.         Case 1
  112.             DocumentFormatDescription = "1 Ole2"
  113.         Case 2
  114.             DocumentFormatDescription = "2 Access 1.x Paintbrush"
  115.     End Select
  116. End Function
  117. Sub Form_Load ()
  118.     Dim Verb As Integer
  119.     LabelLoaded.Caption = ""
  120.     LabelFormat.Caption = ""
  121.     LabelUnsaved.Caption = ""
  122.     Call LoadListObject
  123.     On Error Resume Next
  124.     For Verb = 1 To OLE_MAX_VERBS
  125.         Load mnuObjectVerb(Verb)
  126.     Next Verb
  127.     mnuObjectVerb(0).Visible = False
  128. End Sub
  129. Sub Form_Unload (Cancel As Integer)
  130.     End
  131. End Sub
  132. Sub ListObject_DblClick ()
  133.     Call mnuRecordLoad_Click
  134. End Sub
  135. Sub LoadListObject ()
  136.     Dim sCmd As String
  137.     Dim ss As Snapshot
  138.     'Clear list of items
  139.     ListObject.Clear
  140.     'Create dynaset
  141.     sCmd = "select DocumentName from Document"
  142.     sCmd = sCmd + " order by DocumentName"
  143.     Set ss = db.CreateSnapshot(sCmd)
  144.     Do While Not ss.EOF
  145.         ListObject.AddItem ss("DocumentName")
  146.         ss.MoveNext
  147.     Loop
  148.     ss.Close
  149. End Sub
  150. Sub mnuObject_Click ()
  151.     Dim Verb
  152.     Dim LargestCurrentVerb As Integer
  153.     If Ole1.OLEType = OLE_NONE Then
  154.         mnuObjectDelete.Enabled = False
  155.         mnuObjectEdit.Enabled = False
  156.     Else
  157.         mnuObjectDelete.Enabled = True
  158.         mnuObjectEdit.Enabled = True
  159.         Ole1.Action = OLE_FETCH_VERBS
  160.         LargestCurrentVerb = Ole1.ObjectVerbsCount - 1
  161.           
  162.         For Verb = 1 To LargestCurrentVerb
  163.             mnuObjectVerb(Verb).Caption = Ole1.ObjectVerbs(Verb)
  164.             mnuObjectVerb(Verb).Visible = True
  165.         Next Verb
  166.         
  167.         For Verb = LargestCurrentVerb + 1 To OLE_MAX_VERBS
  168.             mnuObjectVerb(Verb).Visible = False
  169.         Next Verb
  170.     End If
  171. End Sub
  172. Sub mnuObjectDelete_Click ()
  173.     Ole1.Action = OLE_DELETE
  174.     LabelLoaded.Caption = ""
  175.     LabelFormat.Caption = ""
  176.     LabelUnsaved.Caption = ""
  177. End Sub
  178. Sub mnuObjectInsert_Click ()
  179.     If Ole1.OLEType <> OLE_NONE Then
  180.         If MsgBox("Delete Current Object?", 1) = 2 Then
  181.             Exit Sub
  182.         End If
  183.         Ole1.Action = OLE_DELETE
  184.         LabelLoaded.Caption = ""
  185.         LabelFormat.Caption = ""
  186.         LabelUnsaved.Caption = ""
  187.     End If
  188.     Ole1.Action = OLE_INSERT_OBJ_DLG
  189.     If Ole1.OLEType <> OLE_NONE Then
  190.         Ole1.HostName = "Untitled"
  191.         LabelLoaded.Caption = Ole1.HostName
  192.         LabelUnsaved.Caption = "*"
  193.         Ole1.Action = OLE_ACTIVATE
  194.     End If
  195. End Sub
  196. Sub mnuObjectVerb_Click (index As Integer)
  197.     Ole1.Verb = index
  198.     Ole1.Action = OLE_ACTIVATE
  199. End Sub
  200. Sub mnuRecord_Click ()
  201.     If ListObject.ListIndex = -1 Then
  202.         mnuRecordLoad.Enabled = False
  203.         mnuRecordDelete.Enabled = False
  204.     Else
  205.         mnuRecordLoad.Enabled = True
  206.         mnuRecordDelete.Enabled = True
  207.     End If
  208.     If Ole1.OLEType <> OLE_NONE Then
  209.         mnuRecordSave.Enabled = True
  210.     Else
  211.         mnuRecordSave.Enabled = False
  212.     End If
  213. End Sub
  214. Sub mnuRecordDelete_Click ()
  215.     Dim sCmd As String
  216.     If MsgBox("Delete Object " + ListObject.Text + " from Database?", 49) = 2 Then
  217.         Exit Sub
  218.     End If
  219.     MousePointer = 11
  220.     sCmd = "delete from Document"
  221.     sCmd = sCmd + " where DocumentName = """ + ListObject.Text + """"
  222.     db.Execute sCmd
  223.     Call LoadListObject
  224.     MousePointer = 0
  225. End Sub
  226. Sub mnuRecordExit_Click ()
  227.     Unload Me
  228. End Sub
  229. Sub mnuRecordLoad_Click ()
  230.     Dim sCmd As String
  231.     Dim ds As Dynaset
  232.     MousePointer = 11
  233.     'Create dynaset
  234.     sCmd = "select DocumentType, DocumentOle from Document"
  235.     sCmd = sCmd + " where DocumentName = """ + ListObject.Text + """"
  236.     Set ds = db.CreateDynaset(sCmd)
  237.     If ds.EOF Then
  238.         MsgBox "Could not find " + ListObject.Text + "!"
  239.         ds.Close
  240.         MousePointer = 0
  241.         Exit Sub
  242.     End If
  243.     iDocumentType = ds("DocumentType")
  244.     Select Case iDocumentType
  245.         
  246.         Case DOCUMENT_TYPE_ACCESS1XOLE
  247.             Call CopyFieldToAccess1xOle(ds("DocumentOle"), Ole1)
  248.         
  249.         Case DOCUMENT_TYPE_OLE2
  250.             Call CopyFieldToOle2(ds("DocumentOle"), Ole1)
  251.     End Select
  252.     ds.Close
  253.     LabelLoaded.Caption = ListObject.Text
  254.     LabelFormat.Caption = DocumentFormatDescription(iDocumentType)
  255.     LabelUnsaved.Caption = ""
  256.     Ole1.HostName = ListObject.Text
  257.     MousePointer = 0
  258. End Sub
  259. Sub mnuRecordSave_Click ()
  260.     Dim sCmd As String
  261.     Dim ds As Dynaset
  262.     'Set form controls
  263.     frmDocumentName.TextDocumentName.Text = Ole1.HostName
  264.     frmDocumentName.OptionDocumentType(iDocumentType).Value = True
  265.     frmDocumentName.Show 1
  266.     'Test global for good name
  267.     If sDocumentName = "" Then
  268.         Exit Sub
  269.     End If
  270.     MousePointer = 11
  271.     sCmd = "select DocumentName, DocumentType, DocumentOle from Document"
  272.     sCmd = sCmd + " where DocumentName = """ + sDocumentName + """"
  273.     Set ds = db.CreateDynaset(sCmd)
  274.     If ds.EOF Then
  275.         ds.AddNew
  276.         ds("DocumentName") = sDocumentName
  277.     Else
  278.         ds.Edit
  279.     End If
  280.     Ole1.HostName = sDocumentName
  281.     ds("DocumentType") = iDocumentType
  282.     Select Case iDocumentType
  283.         Case DOCUMENT_TYPE_ACCESS1XOLE
  284.             Call CopyAccess1xOleToField(Ole1, ds("DocumentOle"))
  285.         Case DOCUMENT_TYPE_OLE2
  286.             Call CopyOle2ToField(Ole1, ds("DocumentOle"))
  287.     End Select
  288.     ds.Update
  289.     ds.Close
  290.     'Reload list of objects
  291.     Call LoadListObject
  292.     'Call DoEvents so Updated event for Ole control is triggered
  293.     DoEvents
  294.     LabelLoaded.Caption = Ole1.HostName
  295.     LabelFormat.Caption = DocumentFormatDescription(iDocumentType)
  296.     LabelUnsaved.Caption = ""
  297.     MousePointer = 0
  298. End Sub
  299. Sub NewOleObject ()
  300. End Sub
  301. Sub OLE1_Updated (Code As Integer)
  302.     If Code = OLE_CHANGED Then
  303.         LabelUnsaved.Caption = "*"
  304.     End If
  305. End Sub
  306.