home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / blob / blob_tes.frm next >
Text File  |  1994-03-09  |  8KB  |  277 lines

  1. VERSION 2.00
  2. Begin Form BLOB_Test 
  3.    BackColor       =   &H8000000F&
  4.    Caption         =   "BLOB Test Form"
  5.    ClientHeight    =   4296
  6.    ClientLeft      =   816
  7.    ClientTop       =   1476
  8.    ClientWidth     =   6372
  9.    Height          =   4692
  10.    Left            =   780
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   4296
  13.    ScaleWidth      =   6372
  14.    Top             =   1116
  15.    Width           =   6444
  16.    Begin CommandButton Command4 
  17.       Caption         =   "Add New Record"
  18.       Height          =   372
  19.       Left            =   2160
  20.       TabIndex        =   10
  21.       Top             =   3360
  22.       Width           =   1692
  23.    End
  24.    Begin TextBox Text2 
  25.       DataField       =   "Input_Size"
  26.       DataSource      =   "Data1"
  27.       Enabled         =   0   'False
  28.       Height          =   288
  29.       Index           =   2
  30.       Left            =   120
  31.       TabIndex        =   9
  32.       Top             =   3120
  33.       Width           =   972
  34.    End
  35.    Begin TextBox Text2 
  36.       DataField       =   "File_Name"
  37.       DataSource      =   "Data1"
  38.       Enabled         =   0   'False
  39.       Height          =   288
  40.       Index           =   1
  41.       Left            =   120
  42.       TabIndex        =   8
  43.       Top             =   2760
  44.       Width           =   6012
  45.    End
  46.    Begin TextBox Text2 
  47.       DataField       =   "CNT"
  48.       DataSource      =   "Data1"
  49.       Enabled         =   0   'False
  50.       Height          =   288
  51.       Index           =   0
  52.       Left            =   120
  53.       TabIndex        =   7
  54.       Top             =   2400
  55.       Width           =   972
  56.    End
  57.    Begin CommandButton Command3 
  58.       Caption         =   "Write File"
  59.       Height          =   372
  60.       Left            =   4440
  61.       TabIndex        =   4
  62.       Top             =   1800
  63.       Width           =   1812
  64.    End
  65.    Begin CommandButton Command2 
  66.       Caption         =   "Read File"
  67.       Height          =   372
  68.       Left            =   2400
  69.       TabIndex        =   3
  70.       Top             =   1800
  71.       Width           =   1812
  72.    End
  73.    Begin TextBox Text1 
  74.       Height          =   288
  75.       Index           =   1
  76.       Left            =   120
  77.       TabIndex        =   2
  78.       Top             =   1320
  79.       Width           =   6132
  80.    End
  81.    Begin CommonDialog CMDialog1 
  82.       DefaultExt      =   "*.*"
  83.       DialogTitle     =   "Select File"
  84.       Filename        =   "*.*"
  85.       Filter          =   "All  (*.*)|*.*"
  86.       Left            =   5880
  87.       Top             =   0
  88.    End
  89.    Begin CommandButton Command1 
  90.       Caption         =   "Get File Name"
  91.       Height          =   372
  92.       Left            =   120
  93.       TabIndex        =   1
  94.       Top             =   1800
  95.       Width           =   2052
  96.    End
  97.    Begin Data Data1 
  98.       Caption         =   "Data1"
  99.       Connect         =   ""
  100.       DatabaseName    =   "BLOBTEST.MDB"
  101.       Exclusive       =   0   'False
  102.       Height          =   252
  103.       Left            =   2040
  104.       Options         =   0
  105.       ReadOnly        =   0   'False
  106.       RecordSource    =   "Blob_Test_Table"
  107.       Top             =   3840
  108.       Width           =   1872
  109.    End
  110.    Begin TextBox Text1 
  111.       Height          =   288
  112.       Index           =   0
  113.       Left            =   120
  114.       TabIndex        =   0
  115.       Top             =   480
  116.       Width           =   6132
  117.    End
  118.    Begin Label Label1 
  119.       BackColor       =   &H8000000F&
  120.       Caption         =   "Output File && Path Name"
  121.       FontBold        =   -1  'True
  122.       FontItalic      =   0   'False
  123.       FontName        =   "Arial"
  124.       FontSize        =   9.6
  125.       FontStrikethru  =   0   'False
  126.       FontUnderline   =   0   'False
  127.       Height          =   228
  128.       Index           =   1
  129.       Left            =   120
  130.       TabIndex        =   6
  131.       Top             =   1080
  132.       Width           =   3132
  133.    End
  134.    Begin Label Label1 
  135.       BackColor       =   &H8000000F&
  136.       Caption         =   "Input File && Path Name"
  137.       FontBold        =   -1  'True
  138.       FontItalic      =   0   'False
  139.       FontName        =   "Arial"
  140.       FontSize        =   9.6
  141.       FontStrikethru  =   0   'False
  142.       FontUnderline   =   0   'False
  143.       Height          =   228
  144.       Index           =   0
  145.       Left            =   120
  146.       TabIndex        =   5
  147.       Top             =   240
  148.       Width           =   3132
  149.    End
  150. End
  151. Option Explicit
  152.  
  153.  
  154. Declare Function GetModuleFileName Lib "Kernel" (ByVal hModule As Integer, ByVal lpFilename As String, ByVal nSize As Integer) As Integer
  155.  
  156. Sub Command1_Click ()
  157.     CMDialog1.Action = 1
  158.  
  159.     Text1(0) = CMDialog1.Filename
  160.     Text1(1) = "C:\TEMP\" & CMDialog1.Filetitle
  161.  
  162. End Sub
  163.  
  164. Sub Command2_Click ()
  165.  
  166.     If Data1.Recordset.RecordCount = 0 Then
  167.     Data1.Recordset.AddNew
  168.     Data1.Recordset.Update
  169.     End If
  170.     
  171.     If (Len(Text1(0)) = 0) Then
  172.     MsgBox "Require File Name To Read." & Chr(10) & "Select 'Get File Name' first."
  173.     Exit Sub
  174.     End If
  175.  
  176.     ReadBigFile (Text1(0))
  177. End Sub
  178.  
  179. Sub Command3_Click ()
  180.  
  181.     If (Len(Text1(1)) = 0) Then
  182.     MsgBox "Require File Name To Read." & Chr(10) & "Select 'Get File Name' first or edit 'Output File Name'."
  183.     Exit Sub
  184.     End If
  185.  
  186.     WriteBigFile (Text1(1))
  187. End Sub
  188.  
  189. Sub Command4_Click ()
  190.     Data1.Recordset.AddNew
  191.     Data1.Recordset.Update
  192. End Sub
  193.  
  194. Sub Form_Load ()
  195.     Dim temp As String
  196.  
  197.     temp = Left$(App.Path, 1)
  198.     ChDrive temp
  199.     ChDir App.Path
  200.  
  201. End Sub
  202.  
  203. Sub ReadBigFile (FName As String)
  204. 'AppendChunk Method Example
  205. 'This example uses AppendChunk with a data control to save the contents of a separate file into a field.  You would call this
  206. 'procedure with the path and name of the file you want to put into your database.  This procedure works for either Memo or Long
  207. 'Binary fields.
  208.  
  209.     Dim TotalSize As Long, CurChunk As String
  210.     Dim I As Integer, FNum As Integer, ChunkSize As Integer
  211.  
  212.     Screen.MousePointer = 11
  213.  
  214.     ChunkSize = 12000       ' Set size of chunk.
  215.     Data1.Recordset.Edit    ' Enter Edit mode.
  216.     Data1.Recordset.Fields(Field_Name) = "" ' Clear Comments field.
  217.     FNum = FreeFile ' Get free file number.
  218.     Open FName For Binary As #FNum  ' Open the file.
  219.     TotalSize = LOF(FNum)
  220.  
  221.     Text2(1) = FName
  222.     Text2(2) = TotalSize
  223.  
  224.     Do While Not EOF(FNum)
  225.         If TotalSize - Seek(FNum) < ChunkSize Then
  226.             ChunkSize = TotalSize - Seek(FNum)
  227.             If ChunkSize <= 0 Then Exit Do
  228.         End If
  229.         CurChunk = String$(ChunkSize + 1, 32)
  230.         Get #FNum, , CurChunk   ' Read chunk from file.
  231.  
  232.     ' Append chunk to Comments field.
  233.         Data1.Recordset.Fields(Field_Name).AppendChunk (CurChunk)
  234.     Loop
  235.     Data1.Recordset.Update  ' Save the record.
  236.     Close FNum      ' Close the file.
  237.  
  238.     Screen.MousePointer = 0
  239.     MsgBox "Stored file " & FName & Chr(10) & "Input file size = " & TotalSize & Chr(10) & "Into '" & Field_Name & "'."
  240. End Sub
  241.  
  242. Sub WriteBigFile (FName As String)
  243. 'GetChunk and FieldSize Methods Example
  244. 'This example uses GetChunk with a data control to save the contents of a field to a separate file.  You would call this procedure
  245. 'with the path and name of the file where you want to save the contents of the field.  This procedure works for either text or binary
  246. 'fields.
  247.  
  248.  
  249.     Dim NumChunks As Long, TotalSize As Long
  250.     Dim RemChunk As Integer, CurSize As Integer
  251.     Dim I As Integer, FNum As Integer, CurChunk As String
  252.  
  253.     Screen.MousePointer = 11
  254.  
  255.     ChunkSize = 2000        ' Set size of chunk.
  256.     ' Get field size.
  257.     TotalSize = Data1.Recordset.Fields(Field_Name).FieldSize()
  258.     NumChunks = TotalSize \ ChunkSize       ' Set number of chunks.
  259.     ' Set number of remaining bytes.
  260.     RemChunk = TotalSize Mod ChunkSize
  261.     ' Set starting size of chunk.
  262.     CurSize = ChunkSize
  263.     FNum = FreeFile ' Get free file number.
  264.     Open FName For Binary As #FNum  ' Open the file.
  265.     For I = 0 To NumChunks
  266.         If I = NumChunks Then CurSize = RemChunk
  267.         CurChunk = Data1.Recordset.Fields(Field_Name).GetChunk(I * ChunkSize, CurSize)
  268.         Put #FNum, , CurChunk   ' Write chunk to file.
  269.     Next I
  270.     TotalSize = LOF(FNum)
  271.     Close FNum
  272.  
  273.     Screen.MousePointer = 0
  274.     MsgBox "Output file " & FName & Chr(10) & "Output file size = " & TotalSize & Chr(10) & "From '" & Field_Name & "'."
  275. End Sub
  276.  
  277.