Tips SistemThis article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
Lanjutan: Memerlukan ahli coding, interoperabilitas, dan keterampilan multiuser.
Anda dapat menyimpan data besar objek (seperti suara, video, atau grafis data) di
lapangan dengan jenis data OLE objek dalam tabel Microsoft Access. Beberapa
objek data biner yang besar tidak dapat diwakilkan, namun, jika mereka tidak
memiliki server OLE memahami data yang akan disimpan. Anda juga dapat
menyimpan salinan file eksekusi program atau data non-OLE lainnya di
Microsoft Access meja. Jenis data ini disebut sebagai biner besar
objek bitmap (GUMPALAN).
Artikel ini mengasumsikan bahwa Anda sudah familiar dengan Visual Basic untuk
Aplikasi dan membuat aplikasi Microsoft Access menggunakan
pemrograman alat-alat yang disediakan dengan Microsoft Access. Untuk informasi lebih lanjut
tentang Visual Basic for Applications, silakan merujuk ke versi
"Membangun aplikasi dengan Microsoft Access" manual.
Catatan: Visual Basic for Applications disebut akses dasar di Microsoft
Akses versi 1.x dan 2.0. Untuk informasi lebih lanjut tentang akses dasar,
Silakan merujuk ke manual "Pengenalan Pemrograman" dalam Microsoft
Akses versi 1.x atau manual "Bangunan aplikasi" dalam Microsoft
Akses versi 2.0.
Contoh berikut berisi dua contoh yang ditetapkan pengguna fungsi yang Anda
dapat digunakan untuk mengelola sejumlah besar data biner di lapangan dengan OLE
Objek jenis data. Fungsi ditetapkan pengguna yang ReadBLOB() dan
WriteBLOB().
ReadBLOB() fungsi dibaca a ganda disk file dan toko
itu di bidang OLE objek.
Fungsi WriteBLOB() menulis data biner yang disimpan dalam OLE objek
lapangan untuk disk file.
Contoh ini menunjukkan bagaimana untuk menyalin berkas biner ke OLE objek
lapangan, dan kemudian bagaimana untuk menulis kembali ke berkas disk:
Membuat modul baru yang disebut GUMPALAN dan masukkan baris berikut di
modul Deklarasi bagian:
Option Explicit Const BlockSize = 32768
Catatan: Jika Anda bekerja dengan Microsoft akses 2.0, Anda akan perlu untuk
termasuk definisi berikut setelah yang sebelumnya dua:
Catatan: dalam kode contoh berikut, garis bawah (_) pada akhir
baris digunakan sebagai karakter baris-kelanjutan. Menghapus garis bawah
dari akhir baris ketika menciptakan kembali kode ini di akses dasar.
Catatan: Teknik berikut tidak akan bekerja untuk Microsoft Access 1.x.
Untuk Microsoft Access 1.x, Anda akan perlu untuk memodifikasi kode jadi itu
menggunakan variabel Tabel alih-alih Recordset variabel dan OpenTable
fungsi bukan OpenRecordset.
'**************************************************************
' FUNCTION: ReadBLOB()
'
' PURPOSE:
' Reads a BLOB from a disk file and stores the contents in the
' specified table and field.
'
' PREREQUISITES:
' The specified table with the OLE object field to contain the
' binary data must be opened in Visual Basic code (Access Basic
' code in Microsoft Access 2.0 and earlier) and the correct record
' navigated to prior to calling the ReadBLOB() function.
'
' ARGUMENTS:
' Source - The path and filename of the binary information
' to be read and stored.
' T - The table object to store the data in.
' Field - The OLE object field in table T to store the data in.
'
' RETURN:
' The number of bytes read from the Source file.
'**************************************************************
Function ReadBLOB(Source As String, T As Recordset, _
sField As String)
Dim NumBlocks As Integer, SourceFile As Integer, i As Integer
Dim FileLength As Long, LeftOver As Long
Dim FileData As String
Dim RetVal As Variant
On Error GoTo Err_ReadBLOB
' Open the source file.
SourceFile = FreeFile
Open Source For Binary Access Read As SourceFile
' Get the length of the file.
FileLength = LOF(SourceFile)
If FileLength = 0 Then
ReadBLOB = 0
Exit Function
End If
' Calculate the number of blocks to read and leftover bytes.
NumBlocks = FileLength \ BlockSize
LeftOver = FileLength Mod BlockSize
' SysCmd is used to manipulate status bar meter.
RetVal = SysCmd(acSysCmdInitMeter, "Reading BLOB", _
FileLength \ 1000)
' Put the record in edit mode.
T.Edit
' Read the leftover data, writing it to the table.
FileData = String$(LeftOver, 32)
Get SourceFile, , FileData
T(sField).AppendChunk (FileData)
RetVal = SysCmd(acSysCmdUpdateMeter, LeftOver / 1000)
' Read the remaining blocks of data, writing them to the table.
FileData = String$(BlockSize, 32)
For i = 1 To NumBlocks
Get SourceFile, , FileData
T(sField).AppendChunk (FileData)
RetVal = SysCmd(acSysCmdUpdateMeter, BlockSize * i / 1000)
Next i
' Update the record and terminate function.
T.Update
RetVal = SysCmd(acSysCmdRemoveMeter)
Close SourceFile
ReadBLOB = FileLength
Exit Function
Err_ReadBLOB:
ReadBLOB = -Err
Exit Function
End Function
'**************************************************************
' FUNCTION: WriteBLOB()
'
' PURPOSE:
' Writes BLOB information stored in the specified table and field
' to the specified disk file.
'
' PREREQUISITES:
' The specified table with the OLE object field containing the
' binary data must be opened in Visual Basic code (Access Basic
' code in Microsoft Access 2.0 or earlier) and the correct
' record navigated to prior to calling the WriteBLOB() function.
'
' ARGUMENTS:
' T - The table object containing the binary information.
' sField - The OLE object field in table T containing the
' binary information to write.
' Destination - The path and filename to write the binary
' information to.
'
' RETURN:
' The number of bytes written to the destination file.
'**************************************************************
Function WriteBLOB(T As Recordset, sField As String, _
Destination As String)
Dim NumBlocks As Integer, DestFile As Integer, i As Integer
Dim FileLength As Long, LeftOver As Long
Dim FileData As String
Dim RetVal As Variant
On Error GoTo Err_WriteBLOB
' Get the size of the field.
FileLength = T(sField).FieldSize()
If FileLength = 0 Then
WriteBLOB = 0
Exit Function
End If
' Calculate number of blocks to write and leftover bytes.
NumBlocks = FileLength \ BlockSize
LeftOver = FileLength Mod BlockSize
' Remove any existing destination file.
DestFile = FreeFile
Open Destination For Output As DestFile
Close DestFile
' Open the destination file.
Open Destination For Binary As DestFile
' SysCmd is used to manipulate the status bar meter.
RetVal = SysCmd(acSysCmdInitMeter, _
"Writing BLOB", FileLength / 1000)
' Write the leftover data to the output file.
FileData = T(sField).GetChunk(0, LeftOver)
Put DestFile, , FileData
' Update the status bar meter.
RetVal = SysCmd(acSysCmdUpdateMeter, LeftOver / 1000)
' Write the remaining blocks of data to the output file.
For i = 1 To NumBlocks
' Reads a chunk and writes it to output file.
FileData = T(sField).GetChunk((i - 1) * BlockSize _
+ LeftOver, BlockSize)
Put DestFile, , FileData
RetVal = SysCmd(acSysCmdUpdateMeter, _
((i - 1) * BlockSize + LeftOver) / 1000)
Next i
' Terminates function
RetVal = SysCmd(acSysCmdRemoveMeter)
Close DestFile
WriteBLOB = FileLength
Exit Function
Err_WriteBLOB:
WriteBLOB = -Err
Exit Function
End Function
'**************************************************************
' SUB: CopyFile
'
' PURPOSE:
' Demonstrates how to use ReadBLOB() and WriteBLOB().
'
' PREREQUISITES:
' A table called BLOB that contains an OLE Object field called
' Blob.
'
' ARGUMENTS:
' Source - The path and filename of the information to copy.
' Destination - The path and filename of the file to write
' the binary information to.
'
' EXAMPLE:
' CopyFile "c:\windows\winfile.hlp", "c:\windows\winfil_1.hlp"
'**************************************************************
Sub CopyFile(Source As String, Destination As String)
Dim BytesRead As Variant, BytesWritten As Variant
Dim Msg As String
Dim db As Database
Dim T As Recordset
' Open the BLOB table.
Set db = CurrentDb()
Set T = db.OpenRecordset("BLOB", dbOpenTable)
' Create a new record and move to it.
T.AddNew
T.Update
T.MoveLast
BytesRead = ReadBLOB(Source, T, "Blob")
Msg = "Finished reading """ & Source & """"
Msg = Msg & Chr$(13) & ".. " & BytesRead & " bytes read."
MsgBox Msg, 64, "Copy File"
BytesWritten = WriteBLOB(T, "Blob", Destination)
Msg = "Finished writing """ & Destination & """"
Msg = Msg & Chr$(13) & ".. " & BytesWritten & " bytes written."
MsgBox Msg, 64, "Copy File"
End Sub
Membuat tabel baru berikut, dan kemudian menyimpannya sebagai GUMPALAN:
Table: BLOB
------------------------
Field Name: Blob
Data Type: OLE Object
Dengan modul GUMPALAN terbuka dalam Design view, klik Debug jendela (atau
Segera jendela di Microsoft akses 2.0 atau sebelumnya) pada
Menu tampilan.
Ketik baris berikut di jendela Debug, dan kemudian tekan ENTER:
Fungsi ReadBLOB() dan WriteBLOB() salinan Microsoft Windows membantu
file untuk bidang gumpalan GUMPALAN tabel, dan kemudian dari sana ke disk
file bernama Winfil_1.hlp
PENTING: Artikel ini diterjemahkan menggunakan perangkat lunak mesin penerjemah Microsoft dan bukan oleh seorang penerjemah. Microsoft menawarkan artikel yang diterjemahkan oleh seorang penerjemah maupun artikel yang diterjemahkan menggunakan mesin sehingga Anda akan memiliki akses ke seluruh artikel baru yang diterbitkan di Pangkalan Pengetahuan (Knowledge Base) dalam bahasa yang Anda gunakan. Namun, artikel yang diterjemahkan menggunakan mesin tidak selalu sempurna. Artikel tersebut mungkin memiliki kesalahan kosa kata, sintaksis, atau tata bahasa, hampir sama seperti orang asing yang berbicara dalam bahasa Anda. Microsoft tidak bertanggung jawab terhadap akurasi, kesalahan atau kerusakan yang disebabkan karena kesalahan penerjemahan konten atau penggunaannya oleh para pelanggan. Microsoft juga sering memperbarui perangkat lunak mesin penerjemah.
Klik disini untuk melihat versi Inggris dari artikel ini:103257
(http://support.microsoft.com/kb/103257/en-us/
)
Artikel ini berisi tentang produk yang tidak lagi didukung oleh Microsoft. Oleh karena itu, artikel ini disajikan ?sebagaimana adanya? dan tidak akan diperbarui.
Seberapa besar upaya Anda untuk menggunakan artikel ini?
Sangat sedikit
Sedikit
Sedang
Besar
Sangat besar
Berikan saran tentang apa yang dapat kami lakukan untuk menyempurnakan informasi ini
Terima kasih! Masukan Anda akan digunakan untuk membantu kami meningkatkan konten dukungan. Untuk opsi bantuan lainnya, kunjungi Halaman Beranda Bantuan dan Dukungan.