home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form Form1
- Caption = "Form1"
- ClientHeight = 3780
- ClientLeft = 1155
- ClientTop = 1725
- ClientWidth = 6255
- Height = 4185
- Left = 1095
- LinkTopic = "Form1"
- LockControls = -1 'True
- ScaleHeight = 3780
- ScaleWidth = 6255
- Top = 1380
- Width = 6375
- Begin VB.CommandButton cmdPut
- Caption = "Put Object"
- Height = 495
- Left = 4800
- TabIndex = 5
- Top = 960
- Width = 1215
- End
- Begin VB.CommandButton cmdGet
- Caption = "Get Object"
- Height = 495
- Left = 4800
- TabIndex = 4
- Top = 300
- Width = 1215
- End
- Begin VB.CommandButton Command3
- Caption = "Edit"
- Height = 495
- Left = 3060
- TabIndex = 3
- Top = 960
- Width = 1215
- End
- Begin VB.CommandButton Command2
- Caption = "Update"
- Height = 495
- Left = 1680
- TabIndex = 2
- Top = 960
- Width = 1215
- End
- Begin VB.CommandButton Command1
- Caption = "Add"
- Height = 495
- Left = 300
- TabIndex = 1
- Top = 960
- Width = 1215
- End
- Begin VB.TextBox txtName
- DataField = "Name"
- DataSource = "Data1"
- Height = 315
- Left = 720
- TabIndex = 0
- Text = "C:\TEST.TXT"
- Top = 300
- Width = 3555
- End
- Begin VB.Data Data1
- Caption = "Data1"
- Connect = "Access"
- DatabaseName = "C:\BLOBTEST.MDB"
- Exclusive = 0 'False
- Height = 270
- Left = 300
- Options = 0
- ReadOnly = 0 'False
- RecordsetType = 1 'Dynaset
- RecordSource = "Table1"
- Top = 1680
- Width = 5715
- End
- Begin VB.Label Label3
- Caption = "File:"
- Height = 315
- Left = 300
- TabIndex = 8
- Top = 300
- Width = 375
- End
- Begin VB.Label Label2
- Caption = "A helpful code snippet for VB4 programmers --- Frank Font 1996"
- Height = 255
- Left = 240
- TabIndex = 7
- Top = 3360
- Width = 4695
- End
- Begin VB.Label Label1
- Caption = $"OLETEST.frx":0000
- Height = 1035
- Left = 240
- TabIndex = 6
- Top = 2160
- Width = 5775
- End
- Attribute VB_Name = "Form1"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- '----------------------------------------------------------------------
- 'Pass in the name of the file that you want to store in the specified
- 'Access 2.0 OLE OBJECT field. This function will return the size of
- 'the file.
- '----------------------------------------------------------------------
- Public Function CopyOleFromFile(FileName As String, OleField As Field) As Long
- Const BUFFER_SIZE = 4096
- Dim Handle As Integer
- Dim Buffer As String * 4096
- Dim BytesNeeded As Long
- Dim Buffers As Long
- Dim Remainder As Integer
- Dim i As Long
- BytesNeeded = FileLen(FileName)
- Buffers = BytesNeeded \ BUFFER_SIZE
- Remainder = BytesNeeded Mod BUFFER_SIZE
- 'Copy the object chunk by chunk.
- Handle = FreeFile
- Open FileName For Binary Access Read As #Handle
- If BytesNeeded > BUFFER_SIZE Then
- For i = 0 To Buffers - 1
- Get #Handle, , Buffer
- OleField.AppendChunk Buffer
- Next
- End If
- Get #Handle, , Buffer
- OleField.AppendChunk LeftB(Buffer, Remainder)
- Close #Handle
- CopyOleFromFile = BytesNeeded
- End Function
- '----------------------------------------------------------------------
- 'Pass in the name of the file you want to create and the Access 2.0
- 'OLE OBJECT field that contains it. This function will return the size
- 'of the file.
- '----------------------------------------------------------------------
- Public Function CopyOleToFile(FileName As String, OleField As Field) As Long
- Const BUFFER_SIZE = 8192
- Dim Handle As Integer
- Dim Buffer As String
- Dim BytesNeeded As Long
- Dim Buffers As Long
- Dim Remainder As Long
- Dim i As Long
- BytesNeeded = OleField.FieldSize()
- Buffers = BytesNeeded \ BUFFER_SIZE
- Remainder = BytesNeeded Mod BUFFER_SIZE
- 'Copy the object chunk by chunk.
- Handle = FreeFile
- Open FileName For Binary As #Handle
- For i = 0 To Buffers - 1
- Buffer = OleField.GetChunk(i * BUFFER_SIZE, BUFFER_SIZE)
- Put #Handle, , Buffer
- Next
- Buffer = OleField.GetChunk(Buffers * BUFFER_SIZE, Remainder)
- Put #Handle, , Buffer
- Close #Handle
- CopyOleToFile = BytesNeeded
- End Function
- Private Sub cmdGet_Click()
- MsgBox CopyOleFromFile(txtName, Data1.Recordset("Blob")), , "Done"
- End Sub
- Private Sub cmdPut_Click()
- MsgBox CopyOleToFile(txtName, Data1.Recordset![Blob]), , "Done"
- End Sub
- Private Sub Command1_Click()
- Data1.Recordset.AddNew
- End Sub
- Private Sub Command2_Click()
- Data1.Recordset.Update
- End Sub
- Private Sub Command3_Click()
- Data1.Recordset.Edit
- End Sub
-